Given an array of non-null positive integer, and the value of the number of occurrences of the existence of a new dictionary, and sorted by the number of occurrences of

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)

 

 

 

 

  Arch day a soldier.

Guess you like

Origin www.cnblogs.com/qfdmmh/p/10938085.html