iterating in reverse

Nick Vargish nav at adams.patriot.net
Fri Jan 17 14:48:29 EST 2003


Laura Creighton <lac at strakt.com> writes:

> Well, you could reverse the string and operate on that, and then reverse 
> it back ...

You mean kinda like (untested):

l = map(lambda c: c, s)
l.reverse()
i = 0
ret = ''
for ch in l:
    if i and not i % 3:
        ret = ',' + ret 
    ret = ch + ret
    i += 1

Don't need a second reverse, but it doesn't help much. Maybe it's too
much cold symptom suppressor (or not enough?), but this is making me
feel stupid (more so than usual).

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