如何使用Python更新dict值

时间:2015-04-20 14:38:31

标签: python json

我有一个如下字典:

sample_dict = {
      "matchings": [
        {
          "indices": [
            0,
            1,
            2
          ],
          "geometry": "hemo_Ab}gueC????",
          "matched_points": [
            [
              -33.823845,
              -70.619614
            ],
            [
              -33.823845,
              -70.619614
            ],
            [
              -33.823845,
              -70.619614
            ]
          ]
        }
      ]
    }

如何更新几何值?

1 个答案:

答案 0 :(得分:0)

您可以使用以下语法遍历matchings

for i, matching in enumerate(sample_json['matchings']):
    # i is your matching's index
    # matching is your current matching object
    my_new_value = 'something'
    sample_json["matchings"][i]["geometry"] = my_new_value