集合中元素的python顺序 [英] python order of elements in set
本文介绍了集合中元素的python顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白 Python 从保持集应用的顺序.例如:
I do not understand the ordering what Python applies from holding sets. For example:
visited = set()
visited.add('C')
visited.add('A')
visited.add('B')
print(set)
顺序是'A', 'C', 'B'
.为什么A"在C"之前(可能是按字母顺序排列)?为了保留添加顺序,我必须做什么,即 'C', 'A', 'B'
?
The ordering is 'A', 'C', 'B'
. Why 'A' is before 'C' (maybe alphabetical order)?
What I have to do in order to preserve the adding ordering, i.e. 'C', 'A', 'B'
?
推荐答案
你不能有顺序.并且无法知道 Python 是如何对其进行排序的.检查这个答案以寻找替代方案.
You cannot have order in sets. and there is no way to tell how Python orders it. Check this answer for alternatives.
这篇关于集合中元素的python顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文