[Tutor] lazy? vs not lazy? and yielding

spir denis.spir at gmail.com
Fri Mar 5 07:58:15 CET 2010


On Thu, 4 Mar 2010 21:57:18 +0100
Andreas Kostyrka <andreas at kostyrka.org> wrote:

I would rather write it:

> x_it = iter(x)   # get an iterator for x
> try:
>     while True:
>        i = x_it.next()
>        print i
> except StopIteration:
>     pass

x_it = iter(x)   # get an iterator for x
while True:
    try:
        i = x_it.next()
    except StopIteration:
        break
    else:
        print i
(The trial is about getting each new element. The exception breaks the loop. But maybe it's only me.)

Denis
-- 
________________________________

la vita e estrany

spir.wikidot.com



More information about the Tutor mailing list