The order of keys in dictionaries

前端 未结 6 971
渐次进展
渐次进展 2020-11-22 14:32

Code:

d = {\'a\': 0, \'b\': 1, \'c\': 2}
l = d.keys()

print l

This prints [\'a\', \'c\', \'b\']. I\'m unsure of how the metho

6条回答
  •  爱一瞬间的悲伤
    2020-11-22 14:55

    From http://docs.python.org/tutorial/datastructures.html:

    "The keys() method of a dictionary object returns a list of all the keys used in the dictionary, in arbitrary order (if you want it sorted, just apply the sorted() function to it)."

提交回复
热议问题