-1

Need to find out if an 3-itemset list is a superset of at least one 2-itemset. Every 3-itemset that has a frequent size-2 subset is already in your list. The list does not contain duplicated sets.

This is the last code I tried. The output should be a small list of sets if there are any subsets/supersets. With this code though I seem to be getting a larger list instead of a smaller list. Edited...

itemset2 =[{'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''},
 {'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''}]


itemset3 =[{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
 {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
 {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
 {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, 
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
 {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}]

stuff = itemset2

final = [set(y) for y in {frozenset(x) for x in stuff}]

final

nostuff=itemset3
ablanklist=[]
ablanklist2=[]

blanklist=set()
for things in nostuff:
    ablanklist.append(list(things))

for stuff in ablanklist:
    for items in final:
        if stuff[0] and stuff[1] in items:
            print(items)

#print(final)
user14237286
  • 109
  • 10
  • Did you run this code? – Dani Mesejo Dec 06 '20 at 23:58
  • Please provide the expected [MRE](https://stackoverflow.com/help/minimal-reproducible-example). Show where the intermediate results deviate from the ones you expect. We should be able to paste a single block of your code into file, run it, and reproduce your problem. This also lets us test any suggestions in your context. "seem to be going in the opposite direction" is not a problem specification. – Prune Dec 07 '20 at 00:01

2 Answers2

2

The condition is a simple application of any. Given a trio element from three-itemset

if any(pair < trio for pair in two-itemset):

will tell you whether any pair is a subset of the given 3-element set.

Prune
  • 76,765
  • 14
  • 60
  • 81
0
def is_subset(big: set, little: set):
    return little - big == set()

set_a = set([1,2,3])
set_b = set([1,2])
is_subset(set_a, set_b)

edit: better to use the built in set_b.issubset(set_a)

ccluff
  • 163
  • 5