1.利用key排序 d = {'d1':2, 'd2':4, 'd4':1,'d3':3,} for k in sorted(d): print(k,d[k]) d1 2d2 4d3 3d4 1 2.利用value排序:__getitem__ d = {'d1':2, 'd2':4, 'd4':1,'d3':3,} for k in sorted(d,key=d.__getitem__): print(k,d[k]) d4 1d1 2d3 3d2 4 反序:reverse=True d = {'
此程序的目的在于,正确而简单的访问字典的键与值 favorite_languages={ 'jen':['python','c'], 'sarah':['c'], 'edward':['ruby','go'], 'phil':['python','java'], } #古老的方法访问字典中键与值 for element in favorite_languages: print(element +"'s favorite languages are:") print("\t&q