Ordered Dictionary in Python

后端 未结 3 2130
夕颜
夕颜 2020-12-21 02:07

I have a Dictionary in Python such as this: dict = {\'a\':1, \'q\':1, \'l\':2, \'m\':1, \'u\':1, \'i\':1}

Is there any way that I can keep the order of this diction

3条回答
  •  有刺的猬
    2020-12-21 02:45

    Just use 2 for:

    dict = {'a':4, 'q':1, 'l':2, 'm':4, 'p':1}
    
    i = max(dict.values())+1
    for el in range (i):
        for letter in dict:
            if el==dict[letter]:
                print(letter,dict[letter])
    

提交回复
热议问题