In Python, how do I iterate over a dictionary in sorted key order?

后端 未结 10 1012
有刺的猬
有刺的猬 2020-11-27 10:19

There\'s an existing function that ends in the following, where d is a dictionary:

return d.iteritems()

that returns an unsort

10条回答
  •  生来不讨喜
    2020-11-27 10:53

    If you want to sort by the order that items were inserted instead of of the order of the keys, you should have a look to Python's collections.OrderedDict. (Python 3 only)

提交回复
热议问题