Ordering DICT in Python

后端 未结 2 769
一整个雨季
一整个雨季 2021-01-26 10:47

I\'m loading data into a python dict, pulled from coinmarketcap\'s api and then I want to be able to sort it by the rank. I\'ve had a look online and although I\'ve seen some ex

2条回答
  •  执念已碎
    2021-01-26 11:08

    You can't order a dict, but you can create a list of the items and have that sorted:

    sorted(data.iteritems(), key=lambda x:x[1][u'rank'])
    

提交回复
热议问题