On Sat, Sep 13, 2014 at 4:09 PM, Michael Welle <mwe012...@gmx.net> wrote:
> foo = [1,2,3,4]
> it = iter(foo)
>
> for e in it:
>     if e % 2 == 0:
>         x.append(e)

A better way to do this is with a list comprehension:

x = [e for e in foo if e %2 == 0]

Modifying something that you're iterating over is unspecified, I
believe. Certainly it's not a good idea.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to