Welcome, guest | Sign In | My Account | Store | Cart
def group(n, sep = ','):
    s = str(abs(n))[::-1]
    groups = []
    i = 0
    while i < len(s):
        groups.append(s[i:i+3])
        i+=3
    retval = sep.join(groups)[::-1]
    if n < 0:
        return '-%s' % retval
    else:
        return retval

History

  • revision 2 (16 years ago)
  • previous revisions are not available