Someone asked here why when placing 1 and True in set , only 1 supported.
This, of course, is because 1==True . But in what cases is 1 saved and in what cases is true saved?
We'll see:
passing list to construct set instead of using the notation set :
>>> set([True,1]) {True} >>> set([1,True]) {1}
it seems logical: set iterates in the internal list and does not add the second element because it is equal to the first element (note that set([True,1]) cannot give 1 because set cannot know what is inside the list. It may not even be list , but repeatable)
Now using the notation set :
>>> {True,1} {1} >>> {1,True} {True}
It seems that in this case the list of elements is processed in the reverse order (tested on Python 2.7 and Python 3.4).
But is it guaranteed? Or just an implementation detail?
python set python-internals
Jean-François Fabre 01 Sep '17 at 16:17 2017-09-01 16:17
source share