def commify(n):
 if (n is None):
  return None
 n = str(n)
 if ('.' in n):
  (dollars, cents) = n.split('.')
 else:
  (dollars, cents) = (n, None)
 r = []
 for (i, c) in enumerate(str(dollars)[::(-1)]):
  if (i and (not (i % 3))):
   r.insert(0, ',')
  r.insert(0, c)
 out = ''.join(r)
 if cents:
  out += ('.' + cents)
 return out

def commify ( n ) : if ( n is None ) : return None n = str ( n ) if ( '.' in n ) : ( dollars , cents ) = n . split ( '.' ) else : ( dollars , cents ) = ( n , None ) r = [ ] for ( i , c ) in enumerate ( str ( dollars ) [ : : ( - 1 ) ] ) : if ( i and ( not ( i % 3 ) ) ) : r . insert ( 0 , ',' ) r . insert ( 0 , c ) out = '' . join ( r ) if cents : out += ( '.' + cents ) return out
add commas to an integer n .