Sort list by attribute of list

This question already has an answer here:

  • How do I sort a list of dictionaries by values of the dictionary in Python? 17 answers

  • Use a lambda expression , lambda expression would get the dictionary as parameter, and then you can return back the name element from the dictionary -

    lst.sort(key=lambda x: x['name'])
    

    Also, please do not use the list as name of the variable, it will overwrite the built-in list function, which may cause issues when trying to use list(..) function.

    链接地址: http://www.djcxy.com/p/70766.html

    上一篇: 在Python 3.4中按日期排序字典列表

    下一篇: 按列表的属性排序列表