multiple set operations in python

You're correct on all but the students who play exactly two of the sports, which should be:

(C|F|H) - (C^F^H)

Without the A set, the result should find the expected students out of nowhere because they are not part of any other set (by definition). So, the A set is really needed to contain the students that are not part of the other sets.


print(sorted(list(set(C)&set(F)&set(H))))

print(sorted(list(set(C)&set(F)-set(H))))

y=set(C)&set(F)&set(H)

print(sorted(list(((set(C)&set(F))|(set(H)&set(F))|(set(C)&set(H)))-y)))

print(sorted(list(A-(set(C)|set(F)|set(H)))))