Why are tuples constructed from differently initialized sets equal?

前端 未结 4 1136
无人共我
无人共我 2021-02-05 00:48

I expected the following two tuples

>>> x = tuple(set([1, \"a\", \"b\", \"c\", \"z\", \"f\"]))
>>> y = tuple(set([\"a\", \"b\", \"c\", \"z\", \         


        
4条回答
  •  感动是毒
    2021-02-05 01:29

    Sets are not ordered and are defined only by their membership.

    For example, set([1, 2]) == set([2, 1])

    Tuples are equal if their members at each position are equal, but since the collections the tuples were created from iterate equally (in increasing order), tuples end up being equal as well.

提交回复
热议问题