def demo(lis): dic = {} for i in lis: if lis.count(i) > 0: dic[i] = lis.count(i) newdic = sorted(dic.items(), key=lambda items: items[1], reverse=True) return newdic lis = [1, 1, 1, 6, 6, 7, 9, 3] res=demo(lis) print(res)
def demo(lis): dic = {} for i in lis: if lis.count(i) > 0: dic[i] = lis.count(i) newdic = sorted(dic.items(), key=lambda items: items[1], reverse=True) return newdic lis = [1, 1, 1, 6, 6, 7, 9, 3] res=demo(lis) print(res)