Splitting a string into substrings of equal size

Rascal jonrascal at gmail.com
Sat Aug 15 08:08:14 CEST 2009


I'm bored for posting this, but here it is:

def add_commas(str):
    str_list = list(str)
    str_len = len(str)
    for i in range(3, str_len, 3):
        str_list.insert(str_len - i, ',')
    return ''.join(str_list)




More information about the Python-list mailing list