Skip to main content
 首页 » 编程设计

python之按字母顺序对字典排序

2025年05月04日13pengyingh

<分区>

我的程序可以从文件中的字典输出每个学生的姓名和他们的 3 个分数,但我需要按字母顺序对数据进行排序。如何根据姓氏的字母顺序对姓名和分数进行排序?

到目前为止,这是我的代码: 进口泡菜

def clssa(): 
    filename="friendlist.data" 
    f=open('Class6A.txt','rb') 
    storedlist = pickle.load(f) 
    for key, value in storedlist.items(): 
        sorted (key), value in storedlist.items()   
        print (("{} --> {}").format(key, value))