Given a list of dictionaries, how can I eliminate duplicates of one key, and sort by another

前端 未结 7 941
清歌不尽
清歌不尽 2021-01-02 02:31

I\'m working with a list of dict objects that looks like this (the order of the objects differs):

[
    {\'name\': \'Foo\', \'score         


        
7条回答
  •  轮回少年
    2021-01-02 03:19

    I think I can come up with an one-liner here:

    result = dict((x['name'],x) for x in sorted(data,key=lambda x: x['score'])).values()
    

提交回复
热议问题