Python对字典进行排序并返回字典

import operator

dic_instance = {
    '2023/5/25': {'department': '三交一号工作组', 'Attendance_number': '666666', 'Clock_in_time': '2023/5/25 16:05:11',
                  'hms': '16:05:11', 'classes': '缺卡'},
    '2023/4/30': {'department': '三交一号工作组', 'Attendance_number': '666666', 'Clock_in_time': '2023/4/30 19:47:27',
                  'hms': '19:47:27', 'classes': '缺卡'},
    '2023/5/24': {'department': '三交一号工作组', 'Attendance_number': '666666', 'Clock_in_time': '2023/5/24 15:17:19',
                  'hms': '15:17:19', 'classes': '中'},

}

sort_key_dic_instance = dict(sorted(dic_instance.items(), key=operator.itemgetter(0)))  # 按照key值升序

print(sort_key_dic_instance)

你可能感兴趣的:(python,算法,c++)