A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/098618.html below:

Stepping backwards in for loop?

Stepping backwards in for loop? Stepping backwards in for loop?Robin Becker robin at jessikat.fsnet.co.uk
Sat Apr 14 10:28:37 EDT 2001
In article <Xns9083A46CB3B93gustaflalgonetse at 194.213.69.152>, Gustaf
Liljegren <gustafl at algonet.se> writes
>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
>>> s='abcdef'
>>> for i in xrange(len(s)-1,-1,-1):
...     print s[i]
... 
f
e
d
c
b
a

you could also try
>>> for i in xrange(len(s)):
...     print s[-1-i]
...     
-- 
Robin Becker

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4