Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. >>> def commaInsert(s, groupby=3):
  2.     def grouper(itr, groupby):
  3.         i = iter(itr)
  4.         args = [i] * (len(itr) % groupby)
  5.         if args:
  6.             yield ''.join(map(next, args))
  7.         args = [i] * groupby
  8.         while True:
  9.             yield ''.join(map(next, args))
  10.     return ','.join(grouper(s, groupby))
  11.  
  12. >>> commaInsert('1994')
  13. '1,994'
  14. >>> commaInsert('Im born in 1994, and you?')
  15. 'I,m b,orn, in, 19,94,, an,d y,ou?'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement