http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439357
def group(n, sep = ','): s = str(n)[::-1] groups = [] i = 0 while i < len(s): groups.append(s[i:i+3]) i += 3 return sep.join(groups)[::-1] #>>> group(42424242) #'42,424,242'
12378 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
def group(n, sep = ','): s = str(n)[::-1] groups = [] i = 0 while i < len(s): groups.append(s[i:i+3]) i += 3 return sep.join(groups)[::-1] #>>> group(42424242) #'42,424,242'
You need to create an account or log in to post comments to this site.