[Tutor] Amazed

Jacob S. keridee at jayco.net
Sun Nov 14 17:12:20 CET 2004


I believe I agree with both you and Bill.

1) List comprehensions do seem addictive.

However, I did not give you enough code.

newlist = []
for x in something:
    if somethingelse == somethingelse2:
        [newlist.append(somethingelse) for m in ot if m % 2 == 0]
    elif somethingelse == somethingelse3:
        [newlist.append(somethingelse) for m in ot if m % 3 == 0]
      etc,etc,etc.

This shows that newlist is appended to, not written over in each list
comprehension.
That's because I want all of the things in newlist throughout the whole
loop, because I will do something with newlist afterwards.



More information about the Tutor mailing list