I just want to sort by first_name this list in python
list = [ { "profile" : { "first_name" : "a", "last_name" : "b" } } ,
{ "profile" : { "first_name" : "c", "last_name" : "d" } } ,
{ "profile" : { "first_name" : "e", "last_name" : "f" } } ]
这应该这样做:
>>> sorted(lst, key=lambda x: x['profile']['first_name'])
To sort the list itself, use:
lst.sort(key=lambda x: x['profile']['first_name'])
To keep lst
unsorted and return a sorted list use:
sorted(lst, key=lambda x: x['profile']['first_name'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.