Dave wrote:
> This should be simple, but I can't get it:
> 
> How do you loop backwards through a list?
> 
> For example, in, say, Javascript:
> 
> for (var i  = list.length - 1; i >=0; i--) {
>     do_stuff()
> }
> 
> I mean, I could reverse the list, but I don't want to. I want it to
> stay exactly the same, but I want to start at the end and end at the
> beginning.
> 
> Thanks!
> 
> - Dave
> 

for i in reversed(ls):
     do_stuff()

reversed doesn't reverse the list. It returns an iterator that iterates 
through the list backwards.

Cheers,
Carl.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to