l=[1,2,3,4,5,6,1,2,3,5,6] d={} for index in range(len(l)): if l[index] in d: d[l[index]]=d.get(l[index])+1 else: d[l[index]]=1 l=sorted(d.items(),key = lambda x:x[1],reverse = True) for index in range(len(l)): print(l[index])
程序执行结果:
C:\Users\84938\AppData\Local\Programs\Python\Python36\python.exe C:/Users/84938/PycharmProjects/untitled/1.py (1, 2) (2, 2) (3, 2) (5, 2) (6, 2) (4, 1) Process finished with exit code 0