diff lists
Mike C. Fletcher
mcfletch at home.com
Wed Mar 28 08:48:25 EST 2001
>>> a= ['a', 'b', 'c', 'd', 'e', 'f']
>>> b = ['e', 'c', 'f']
>>> [ element for element in a if element not in b ] # python 2.0+
['a', 'b', 'd']
>>> filter( lambda x, y=b: x not in y, a ) # any python
['a', 'b', 'd']
>>>
That's not efficient for huge lists, but fine for short ones.
HTH,
Mike
-----Original Message-----
From: Oliver Vecernik [mailto:vecernik at aon.at]
Sent: Wednesday, March 28, 2001 7:47 AM
To: python-list at python.org
Subject: diff lists
Hi,
I've got following two lists:
['a', 'b', 'c', 'd', 'e', 'f']
['e', 'c', 'f']
I'd like to have the result:
['a', 'b', 'd']
The list need not to be ordered. ['d', 'a', 'b'] will also be ok. What
is the most effective way to achive that result?
Oliver
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list