[Zope-dev] Intersection (set) in Zope
Amos Latteier
amos@aracnet.com
Thu, 09 Sep 1999 09:31:10 -0700
At 07:13 AM 9/9/99 -0800, Jason Spisak wrote:
>Does anyone know if Zope already has (I'll bet it does, it's just a
>matter of finding it, which I haven't yet) an object or method for
>intersection or set of two lists. I want items common to both lists.
>It's a simple python external method, but why write code t hat's already
>written. I combed the dtml guide and the source in places and can't see
>what it would be called. Any ideas?
There is the intSet module which gives you a cool intSet object which
supports intersection, union, and difference.
However, if you don't have enormous lists and/or your list items aren't
integers it's probably fine to do this:
def intersection(list1, list2):
result=[]
for item in list1:
if item in list2:
result.append(item)
return result
Good luck.
-Amos