Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why min({1},{0}) returns {1} [duplicate]

Tags:

python

min

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

min({0},{1})

returns {0}, while

min({1},{0})

returns {1}?

like image 865
Adam Ježek Avatar asked Dec 03 '22 22:12

Adam Ježek


1 Answers

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.

like image 180
Bernhard Avatar answered Dec 11 '22 15:12

Bernhard