list of unique non-subset sets
les_ander at yahoo.com
les_ander at yahoo.com
Thu Mar 17 14:35:15 EST 2005
Hi,
I have many set objects some of which can contain same group of object
while others can be subset of the other. Given a list of sets,
I need to get a list of unique sets such that non of the set is an
subset of another or contain exactly the same members.
Tried to do the following:
s1=set(['a','b','c'])
s2=set(['a','c'])
s3=set(['a','d','e','f'])
s4=set(['r','k','l'])
s5=set(['r','k','l'])
L=[s1,s2,s3,s4,s5]
----------------------- > cleaned-up list should contain s1, s3, s5
Lu=[] # unique list of sets
Lu.append( L[0] )
for i in range(1,len(L)):
s=L[i]
# check for equality
if s in L:
continue
# check for subseting
for j in len(Lu):
s1=Lu[j]
if len (s-s1)==0:
continue
elif len(s1-s)==0:
Lu[i]=s1 # replace with the bigger
But this does not work since I get
Lu=[set(['a', 'c', 'b'])]
What am I doing wrong?
thanks
More information about the Python-list
mailing list