iterating in reverse

Nick Vargish nav at adams.patriot.net
Fri Jan 17 21:39:31 CET 2003


Richard Kuhns <rjkuhns at geetel.net> writes:
> def comify(number):
>     import re
>     string, count = re.subn(r'^(-?\d+)(\d\d\d)', r'\1,\2', str(number))
>     while count > 0:
>         string, count = re.subn(r'^(-?\d+)(\d\d\d)', r'\1,\2', string)
>     return string

I don't much care about efficiency, but this looks expensive... :^) I
had been thinking about a re solution -- being an ex-perl person it
was an inevitable thought -- thank you for demo'ing one.

Nick

-- 
# sigmask.py  ||  version 0.2  ||  2003-01-07  ||  Feed this to your Python.
print reduce(lambda x,y:x+chr(ord(y)-1),'Ojdl!Wbshjti!=obwAqbusjpu/ofu?','')





More information about the Python-list mailing list