remove matching pairs

Evan evanmason at gmail.com
Thu Dec 14 06:21:33 EST 2006


Is there a simple way to to identify and remove matching pairs from 2
lists?

For example:

I have

a=[2, 5, 3, 4, 7, 2, 2, 4, 8, 1]
b=[7, 3, 5, 8, 1, 7, 4, 8, 2, 6]

and I want to get this:

a=[2, 5, 3, 4, 7, 2, 8, 1]
b=[7, 3, 5, 8, 1, 4, 2, 6]

There are recurring pairs of (2, 7) and (4, 8), and so I want to remove
one of each pair.

Many thanks, Evan




More information about the Python-list mailing list