Beginner : removing tuples from a list

Fabrizio facelle at
Sat Feb 8 21:03:41 CET 2003


I have a list containing tuples ("records") :

t = [(1,'john','usa'),(2,'jim','uk',),(3,'jeanne','f'),(4,'jack','usa')]

I want to remove all the "european records". I tried the following, but it
doesn't work  :

europe = ['uk','f']

x = 0
for z in t :
    if z[2] in europe :
    x = x +1

print t

>>> [(1, 'john', 'usa'), (3, 'jeanne', 'f'), (4, 'jack', 'usa')]

But Jeanne is still there...

TIA for your help


More information about the Python-list mailing list