Stepping backwards in for loop?
Robert Amesz
rcameszREMOVETHIS at dds.removethistoo.nl
Sat Apr 14 15:39:35 EDT 2001
Gustaf Liljegren wrote:
> Can't figure out how to step backwards, character by character in a
> string. I was looking for a loop countruct with a counter to handle
> this, but the for loop in Python doesn't let me step backwards.
> What is the alternative?
>
> Gustaf
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> for i in range(10,0,-1):
... print i,
...
10 9 8 7 6 5 4 3 2 1
>>>
Now, that wasn't too hard, was it? ;-)
Another two bits of advice:
1 - As a Windows-user, pick up the Python documentation in HTML-help
format (.CHM). It's somewhere on Robin Dunn's pages, IIRC. Being
able to search for keywords reaaly helps to speed things up.
2 - Totally unrelated to Python: upgrade to the latest Xnews, there's a
new official release out, with a bucketload of new nifty features.
You'll love it.
Robert Amesz
More information about the Python-list
mailing list