Python-使用min()在JSON对象中查找min值?

Python-使用min()在JSON对象中查找min值?,python,json,geojson,min,Python,Json,Geojson,Min,我有一个geojson对象,它有: "features" : [{"properties": {"rank": 10}},{"properties": {"rank": 2}}] 等等。我想找到最小秩并使用该方法。所以我试过这样的方法: features = geojson["features"] min(features["properties"]["rank"]) 然后: features = geojosn["features"]["properties"]["rank"] min(f

我有一个geojson对象,它有:

"features" : [{"properties": {"rank": 10}},{"properties": {"rank": 2}}]
等等。我想找到最小秩并使用该方法。所以我试过这样的方法:

features = geojson["features"]
min(features["properties"]["rank"])
然后:

features = geojosn["features"]["properties"]["rank"]
min(features)
这两方面都有:

TypeError:列表索引必须是片的整数,而不是str


我做错了什么?任何帮助都将不胜感激,谢谢

我假设您有一个包含属性的功能列表(正如@idjaw指出的,您的数据结构无效)。然后,
geojson['features']
是一个列表,您不需要为该列表编制索引。可以使用生成器执行此操作:

min(feature["properties"]["rank"] for feature in geojson['features'])
或者,如果您想要恢复整个功能,则可以使用以下键:

min(geojson['features'], key=lambda feature: feature["properties"]["rank"])

我假设您有一个带有属性的特性列表(正如@idjaw指出的,您的数据结构无效)。然后,
geojson['features']
是一个列表,您不需要为该列表编制索引。可以使用生成器执行此操作:

min(feature["properties"]["rank"] for feature in geojson['features'])
或者,如果您想要恢复整个功能,则可以使用以下键:

min(geojson['features'], key=lambda feature: feature["properties"]["rank"])

但是基本上,
feature
在这里充当列表迭代器,循环遍历features的元素?谢谢你的回答!!:)但是基本上,
feature
在这里充当列表迭代器,循环遍历features的元素?谢谢你的回答!!:)