pythonlistsetaprioripruning

How do I find out if at least one 2-itemsets is in a 3-itemsets list?


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)

Solution

  • 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.