Sort list by attribute of list
This question already has an answer here:
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.
下一篇: 按列表的属性排序列表