python dict sorted


  • 1
    R
            dicts={}
            for i in nums:
                dicts[i]=dicts.get(i,0)+1
    
            lists = sorted(dicts.items(), key=lambda item:item[1],reverse=True)
            
            ret=[]
            for i in lists:
                ret.append(i[0])
            return ret[0:k]
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.