fork download
  1. import re
  2.  
  3. try:
  4. while True:
  5. x = input()
  6. print(re.sub(r"(.)(?=(...)+$)", "\\1,", x))
  7. except (EOFError):
  8. pass
Success #stdin #stdout 0.04s 9672KB
stdin
1
12
123
1234
12345
123456
1234567
12345678
123456789
1234567890
12345678901
123456789012
stdout
1
12
123
1,234
12,345
123,456
1,234,567
12,345,678
123,456,789
1,234,567,890
12,345,678,901
123,456,789,012