Why min ({1}, {0}) returns {1}

Function

min () should return the smallest of the given numbers. Then why

min({0},{1})

returns {0}, and

min({1},{0})

returns {1}?

+4
source share
3 answers

In python suites, they are compared based on whether one is a subset of the other.

No - this is a subset of the other, therefore <it gives Falsein all cases, therefore the first is returned.

So, {1}<{0}gives Falseexactly the same as {2}<{1}gives Falseand {2}<{3,4,5}gives False. However {1,2}<{1,3,2}gives True. This means that the general order is not defined on the set .

+7
source

" " :

set < other

, , set <= other set!= other.

{0} < {1} == False {1} < {0} == False, "" , min.

+5

Because it sets , not numbers .

In addition, it should return {1}, not 1, as you can see here:

>>> min({0},{1})
set([0])
>>> min({1},{0})
set([1])

This means that it will return a set, not a number.

+4
source

Source: https://habr.com/ru/post/1678786/


All Articles