Skip to main content
added 10 characters in body
Source Link
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.

Python 2, 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.

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.

added 532 characters in body
Source Link
ElPedro
  • 6.5k
  • 2
  • 24
  • 38

Python 2, 8474 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 inputReverse the input
  • Step throughthrough backwards in threes appendingappending prepending the next letter
  • Reverse and printReverse and print

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

Python 2, 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 in threes appending 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.

Python 2, 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.

Source Link
ElPedro
  • 6.5k
  • 2
  • 24
  • 38

Python 2, 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 in threes appending 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.