Does converting a list to a set change the order of elements?

后端 未结 2 931
鱼传尺愫
鱼传尺愫 2021-01-21 21:31

When I do something like:

U = [(1.0, 0.0), (0.0, 1.0)]
set(U)

It gives me:

{(0.0, 1.0), (1.0, 0.0)}

I just w

2条回答
  •  猫巷女王i
    2021-01-21 22:29

    I think what is confusing you is the symmetric nature of the tuples. Converting the list to a set has not affected the arrangement of items in the tuples but rather the order of the tuples. And that is because sets are unordered by nature. Here is another example with asymmetric tuples.

    >>> U = [(2.0, 0.0), (0.0, 1.0)]
    >>> set(U)
    {(0.0, 1.0), (2.0, 0.0)}
    

提交回复
热议问题