Beginner : removing tuples from a list

Fabrizio facelle at libero.it
Sat Feb 8 15:03:41 EST 2003


Hi,

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 :
        t.pop(x)
    x = x +1

print t

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

But Jeanne is still there...

TIA for your help


Fabrizio








More information about the Python-list mailing list