Beginner : removing tuples from a list

Rene Pijlman reageer.in at de.nieuwsgroep
Sat Feb 8 15:28:38 EST 2003


Fabrizio:
>t = [(1,'john','usa'),(2,'jim','uk',),(3,'jeanne','f'),(4,'jack','usa')]
>europe = ['uk','f']
>
>x = 0
>for z in t :
>    if z[2] in europe :
>        t.pop(x)

This last statement modifies t during the loop.

Try this instead:

    print [x for x in t if x[2] not in europe]

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl




More information about the Python-list mailing list