I was looking through Numpy source code here, and I found the following piece of code, which ensures that the user is not passing both 'C'
and 'F'
to the requirements
argument.
if requirements >= {'C', 'F'}:
raise ValueError('Cannot specify both "C" and "F" order')
I was intrigued about how one could use >=
to make such a check. I found this answer on SO, and this in the python docs. From these I learned that using the lexical order, it first compares the two first elements, if they are equal, look at the next element, if they are different, this determines which is the lesser.
When I try this with an example that the user passes the arguments 'A', 'C', 'F'
, list
or tuple
works as expected, but when I try with a set
, I get a different result:
['A', 'C', 'F'] >= ['C', 'F'] # False
('A', 'C', 'F') >= ('C', 'F') # False
{'A', 'C', 'F'} >= {'C', 'F'} # True
I tried to research lexical ordering specifically for sets, but since set is also used in the "mathematical" sense, most examples and articles I find use lists
. So why is the comparison between sets
different?