Dnia 15-08-2009 o 08:08:14 Rascal <[email protected]> wrote:
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)
For short strings (for sure most common case) it's ok: simple and clear.
But for huge ones, it's better not to materialize additional list for the
string -- then pure-iterator-sollutions would be better (like Gabriel's or
mine).
Cheers,
*j
--
Jan Kaliszewski (zuo) <[email protected]>
--
http://mail.python.org/mailman/listinfo/python-list