Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two sets in python

Tags:

python

set

Why do I get the results shown?

>>> x = {"a","b","1","2","3"}  
>>> y = {"c","d","f","2","3","4"}  
>>> z=x<y        
>>> print(z)
False
>>> z=x>y
>>> print(z)
False
like image 680
Sai Swaroop Naidu Avatar asked Nov 28 '22 07:11

Sai Swaroop Naidu


1 Answers

The < and > operators are testing for strict subsets. Neither of those sets is a subset of the other.

{1, 2} < {1, 2, 3}  # True
{1, 2} < {1, 3}  # False
{1, 2} < {1, 2}  # False -- not a *strict* subset
{1, 2} <= {1, 2}  # True -- is a subset
like image 135
FHTMitchell Avatar answered Dec 28 '22 14:12

FHTMitchell