Another method is to build two sets of sets, one for E1 and one for E2, then make the intersection of these sets

- with Python 2.3

>>> E1=[('a','g'),('r','s')]
>>> E2=[('g','a'),('r','q'),('f','h')]
>>> from sets import Set,ImmutableSet
>>> f=Set([ImmutableSet(s) for s in E1])& Set([ImmutableSet(s) for s in E2])
>>> [tuple(x) for x in f]
[('a', 'g')]


- with Python 2.4

>>> E1=[('a','g'),('r','s')]
>>> E2=[('g','a'),('r','q'),('f','h')]
>>> f=set([frozenset(s) for s in E1]) & set([frozenset(s) for s in E2])
>>> [tuple(x) for x in f]
[('a', 'g')]

You must use ImmutableSet or frozenset to be able to create a set of sets

Pierre
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to