Can internal dictionary order change?

前端 未结 3 751
一生所求
一生所求 2021-01-19 04:08
exampleDict = {\'a\':1, \'b\':2, \'c\':3, \'d\':4}

The above dictionary initially iterated through in this order:

b=2
d=4
a=1
c=3
<         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-19 04:44

    Curious about why you want them ordered. Any chance it's just for consistent logging/printing or similar? If so, you can sort the keys alphabetically. See other article: How to sort dictionary by key in numerical order Python

提交回复
热议问题