Is python's “set” stable?

后端 未结 7 1100
渐次进展
渐次进展 2020-11-29 07:21

The question arose when answering to another SO question (there).

When I iterate several times over a python set (without changing it between calls), can I assume it

7条回答
  •  自闭症患者
    2020-11-29 08:05

    The definition of a set is unordered, unique elements ("Unordered collections of unique elements"). You should care only about the interface, not the implementation. If you want an ordered enumeration, you should probably put it into a list and sort it.

    There are many different implementations of Python. Don't rely on undocumented behaviour, as your code could break on different Python implementations.

提交回复
热议问题