蟒蛇排序JSON文件我有JSON文件:使用具有值作爲字符串
ll = {"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"James", "lastName":"Bond"},
{"firstName":"Celestial", "lastName":"Systems"},
{"firstName":"Peter", "lastName":"Jones"}
]}
我想通過鍵(姓氏或名字)
我知道,我們用數字作爲使用的排序方法進行排序值,但我無法按字符串的值排序。
下面我想:
#data = json.load(file)
new = sorted(data, key = lambda k: k['employees'].get('lastName',0))
,並收到錯誤:
TypeError: string indices must be integers