min() function should return the smallest of the numbers given. Then why
min({0},{1})
returns {0}, while
min({1},{0})
returns {1}?
min() function should return the smallest of the numbers given. Then why
min({0},{1})
returns {0}, while
min({1},{0})
returns {1}?
In python sets are compared based on whether or not one is a subset of the other.
None is a subset of the other, so <
gives False
in all cases, so the first one is returned.
So {1}<{0}
gives False
just like {2}<{1}
gives False
and {2}<{3,4,5}
gives False.
However {1,2}<{1,3,2}
gives True
.
This means there is no total order defined on sets.
The comparison operators for sets check for "subset" not for numerical comparisons:
set < other
Test whether the set is a proper subset of other, that is, set <= other and set != other.
And both your sets are disjoint so {0} < {1} == False
and {1} < {0} == False
so it will always return the "first" set you put into min
.
Because these are sets, not numbers.
Moreover, it should return {1}, not 1, as you can see here:
>>> min({0},{1})
set([0])
>>> min({1},{0})
set([1])
That means that it will return the set, not the number.