[Tutor] List intersect
Pawel Kraszewski
Pawel_Kraszewski at wp.pl
Tue Sep 28 09:05:40 CEST 2004
Hello!
I guess it may be done like this:
>>> import sets
>>> a=sets.Set()
>>> a=a.union(['a','b','c'])
>>> print a
Set(['a', 'c', 'b'])
>>> a=a.union(['b','c','d'])
>>> print a
Set(['a', 'c', 'b', 'd'])
So, for the price of loosing original order of items, we have pretty intuitive
usage. 'Set' keeps one copy of item, no matter how many times added.
Oh, by the way - 'list intersect' is a common part of intersecting lists (the
result would be just ['b','c']). You are talking of list union. Being a
teacher I couldn't resist. :)
Hope it helps.
--
Pawel Kraszewski FreeBSD/Linux
E-Mail/Jabber Phone ICQ GG
Pawel_Kraszewski at wp.pl +48 604 777447 45615564 69381
More information about the Tutor
mailing list