Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> def commaInsert(s, groupby=3):
- def grouper(itr, groupby):
- i = iter(itr)
- args = [i] * (len(itr) % groupby)
- if args:
- yield ''.join(map(next, args))
- args = [i] * groupby
- while True:
- yield ''.join(map(next, args))
- return ','.join(grouper(s, groupby))
- >>> commaInsert('1994')
- '1,994'
- >>> commaInsert('Im born in 1994, and you?')
- 'I,m b,orn, in, 19,94,, an,d y,ou?'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement