Back to questions
JuniorTheoryCommon
What does this program print?
baskets = [
{"tea", "sugar"},
{"tea", "lemon", "sugar"},
{"coffee", "sugar"},
{"tea", "lemon"},
]
itemset = {"tea", "sugar"}
count = sum(1 for b in baskets if itemset <= b)
print(count / len(baskets))0.5
- Expecting
1.0: on sets<=is the subset test, not a size comparison, so a basket counts only if it holds bothteaandsugar. - Expecting
0.25:<=lets a basket hold extra items, so the basket withlemoncounts as well; only==demands an exact match.
- What would the program print with
==in place of<=? - How would the support change if a fifth basket held only
tea?