Problem with using sets and issubset in Python
Solution 1:
As written, some_cords
is a set with 3 elements, each one is a tuple: (1, 2)
, (2, 2)
and (3, 2)
. On the other hand, line_cords
is a set of 4 tuples, each tuple being a tuple of length 3.
Adding parenthesis around the tuples of some_cords
will turn it into a set with one element similar to the ones of line_cords
:
some_cords = {((1, 2), (2, 2), (3, 2))}
and the first test will return True
As for the second test (using in
), some_cords
is a set
, and each element of line_cords
is a tuple, so it will always return False
. This test would be OK if some_cords
was a tuple: you can achieve this removing the braces, but then you can not use issubset
.