从深度嵌套的字典中选择条目

问题描述 投票:0回答:1

我有一个非常嵌套的字典(geojson),其中包含具有特征的shapefile。这些功能之一是我想通过其选择数据的“ month_num”。问题在于该词典是深层嵌套的。我想到的最接近的是以下内容:

list(filter(lambda country: ['features'][country]['properties']['month_num'] == 2, geojson_countries))

但是这给了我以下错误:

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

geojson文件看起来像这样:

enter image description here

我希望能够选择所有具有'month_num'== 2的条目。

有人可以帮忙吗?

python json dictionary geojson
1个回答
0
投票

您可能会相处

features = [item for item in your_dict["features"] 
            if item["properties"]["month_num"] == 2]
© www.soinside.com 2019 - 2024. All rights reserved.