我有一个非常深层次的嵌套字典(geojson),其中包含带有特性的shapefiles。这些特性之一是“month_num”,我想通过它来选择数据。问题是这本字典嵌套得很深。我想出的最接近的事情是:
list(filter(lambda country: ['features'][country]['properties']['month_num'] == 2, geojson_countries))但这给了我以下错误:
TypeError:列表索引必须是整数或切片,而不是str。
geojson文件如下所示:

我希望能够选择所有有'month_num‘== 2的条目。
有人能帮忙吗?
发布于 2020-04-13 21:03:02
你可能会相处的
dct = your_dict.copy()
dct["features"] = [item for item in dct["features"]
if item["properties"]["month_num"] == 2]https://stackoverflow.com/questions/61196555
复制相似问题