Skip to main content
3 of 3
added 10 characters in body
ElPedro
  • 6.5k
  • 2
  • 24
  • 38

Python 2, 84 74 bytes

i=input();o=""
for x in"kMGT ":o=(i,x+i[-3:])[len(i)>3]+o;i=i[:-3]
print o

Try it online!

Previous version for 84 bytes

i=input()[::-1];o=""
for x in"kMGT ":o+=(i,i[0:3]+x)[len(i)>3];i=i[3:]
print o[::-1]

Try it online!

  • Reverse the input
  • Step through backwards in threes appending prepending the next letter
  • Reverse and print

Not sure that this is the most efficient approach but it's the best I can come up with at the moment.

ElPedro
  • 6.5k
  • 2
  • 24
  • 38