how to write a C-style for loop?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Feb 15 19:29:16 EST 2006


Steven D'Aprano>That's a completely different question, so of course it
has a completely different answer. Here is one way:<

Other versions without the creation of a list:

for i in (2**n for n in xrange(6)):
    do_something(i)

for i in (1<<n for n in xrange(6)):
    do_something(i)

for i in xrange(6):
    do_something(i<<i)

Bye,
bearophile




More information about the Python-list mailing list