[Zope-dev] Intersection (set) in Zope

Jason Spisak webmaster@MTEAR.COM
Thu, 09 Sep 1999 10:09:00 -0800


A simple external method like this is even in Mark Lutz's book, but I
wanted to see if this was ground covered inside Zope somewhere.  Doesn't
ZCatalog do intersections?  My lists aren't big, so I'll probably use
that external method.

Thanks Amos.

Jason

Amos Latteier wrote:
> 
> 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