intersection
Erno Kuusela
erno at iki.fi
Thu May 25 19:38:44 EDT 2000
>>>>> "Thomas" == Thomas Thiele <thiele at muc.das-werk.de> writes:
Thomas> l1 = [1,2,3,4,5] l2 = [4,5,6,7,8]
Thomas> l3 should be [4,5]
Thomas> It' s not diffucult to program it, but I couldn't find a
Thomas> build-in-fucnction. Or I'm blind?
there is no built-in for this as far as i know.
just use a dictionary:
>>> l1 = [1,2,3,4,5]; l2 = [4,5,6,7,8]
>>> d = {}
>>> for item in l1:
... d[item] = 42
...
>>> l3 = filter(d.has_key, l2)
>>> l3
[4, 5]
if you are doing a lot of set-ish things, it might be a
good idea to have a look at kjBuckets at
<URL:http://starship.python.net/crew/aaron_watters/kjbuckets/
kjbuckets.html>.
-- erno
More information about the Python-list
mailing list