Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python更新dict值_Python_Json - Fatal编程技术网

如何使用Python更新dict值

如何使用Python更新dict值,python,json,Python,Json,我有一本字典如下: sample_dict = { "matchings": [ { "indices": [ 0, 1, 2 ], "geometry": "hemo_Ab}gueC????", "matched_points": [ [ -33.823845,

我有一本字典如下:

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
            ]
          ]
        }
      ]
    }

如何更新几何体值?

您可以使用以下语法循环您的
匹配

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

sample_json[“matchings”][0][“geometry”]=“which”
这是一个.json文件还是.py文件?如果项目编号未知怎么办?我该如何循环使用它呢?那么它不是一个“json”,而是一个Python
dict
谢谢Jivan。我从json创建了dict。你说得对,现在这是一个命令。