loops

John Machin sjmachin at lexicon.net
Sat Oct 18 23:45:47 EDT 2008


On Oct 19, 2:30 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
[snip]
> making your code easy to read and easy to maintain is far more important.
>
> for x in (2**i for i in xrange(10)):
>     print x
>
> will also print 1, 2, 4, 8, ... up to 1000.

I would say up to 512; perhaps your understanding of "up to" differs
from mine.

Easy to read? I'd suggest this:

for i in xrange(10):
    print 2 ** i

Cheers,
John



More information about the Python-list mailing list