operator_dict={'<':'less than','==':'equal'}
print('Here is the original dict:')
for x in sorted(operator_dict):
print(f'Operator {x} means {operator_dict.get(x)}.')
print(" ")
operator_dict['>']='greater than'
print("The dict was changed to:")
operator_dict_sorted =sorted(operator_dict.items())
for key, value in operator_dict_sorted:
print(f'Operator {key} means {value}.')
注意sorted只对key进行排序

京公网安备 11010502036488号