从这个来源: https://www.geeksforgeeks.org/python-get-key-from-value-in-dictionary/
我想知道为什么会这样
# creating a new dictionary
my_dict ={"java":100, "python":112, "c":11}
# list out keys and values separately
key_list = list(my_dict.keys())
val_list = list(my_dict.values())
print(key_list[val_list.index(100)])
print(key_list[val_list.index(112)])
我理解代码,但我认为字典没有存储任何内部顺序,那么.keys()和.values()方法如何/为什么保持顺序
这里是python新手
谢谢
自从Python 3.6以来
dict
在实现新的紧凑字典类型后保持了顺序What's New in Python 3.6 New dict implementation
从Python3.7开始上述内容不再是实现细节,而
dict
维护秩序成为官方语言细节[Python-Dev] Guarantee ordered dict literals in v3.7?
相关问题 更多 >
编程相关推荐