Adding Commas To Digits
Join the DZone community and get the full member experience.Join For Free
Copy from Marek Baczynski's code here 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'
Opinions expressed by DZone contributors are their own.