On 3/17/11 2:17 PM, Denis Bitouzé wrote:
Hi,

is there a better way than loops to get the intersection of (2) groups?

Assuming you have a list of ids or objects for each group
I would cast them to a set and take the intersection.
See, e.g,
http://docs.python.org/library/stdtypes.html#set-types-set-frozenset

Something like (pseudo code)

common = set(g1.listMemberIds()) & set(g2.listMemberIds())

Or interactively (Python 2.6)
>>> l1 = [1,2,3,4]
>>> l2 = [3,4,5,6]
>>> c = set(l1) & set(l2)
>>> c
set([3, 4])

This can be applied to more than 2 groups/sets as well.

Raphael


Thanks.


_______________________________________________
Setup mailing list
Setup@lists.plone.org
https://lists.plone.org/mailman/listinfo/setup

Reply via email to