按序输出 列表里套字典

img


怎么能在我这个代码基础上,实现学号升序输出呢
不要列表也可以 能让他升序就行

img


lst = []

while True:
    student_dict = {}
    no = input('学号:')
    student_dict['学号'] = no
    lst.append(student_dict)
    choice = input('继续吗?(y/n)')
    if choice.lower() in ['y', 'yes']:
        continue
    else:
        break

sorted_lst = sorted(lst, key=lambda x: x['学号'])  # 按学号升序排序
print(sorted_lst)

lst进行排序:lst.sort(key=lambda x : x["学号"]),完整代码如下:

lst = []
while True:
    dict = {}
    no = input("学号:")
    dict["学号"] = no
    lst.append(dict)
    choice = input("继续吗:")
    if choice in ['Y', 'y']:
        continue
    else:
        break
#增加排序
lst.sort(key=lambda x : x["学号"])
print(lst)