How to update a dict value with Python

ustroetz

I have a dictionary like the following:

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

How can I update the geometry value?

Jivan

You can loop through your matchings with this syntax:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

In ansible, how to update a value of a dict withing a loop into a list of dict

Python: Fast way to update value in dict based on length of text?

How to append a key before a value in Python dict?

How to loop through this Python dict and search if value is there

How to make dict element value as list in Python

How iterate (key, value) boost::python:dict

Python dbf: How to update a value?

How to update a dictionary value in python

Python change dict value

Sorting python by value in a value dict

python to update dict values in list

How to sort dict by value

How to update a dict nested in another?

Python dict ordering by inner dict value

accessing dict within dict value python

Extract dict value from list of dict in python

How to map list of strings containing key value to dict in Python?

python 3 how to add key:value to nested dict in json

How to find mean of a value array inside a dict in Python?

How do i find the largest value of an item in a nested dict in python?

How to set default value to all keys of a dict object in python?

How to initialize a dict with keys from a list and empty value in Python?

How to change value for item in a list of dict in python in a simple way?

Python: how to get a dict key given its value without looping?

Python: how to remove a value from a dict if it exactly matches the key?

How to print more than one value from nested dict in Python

How to send dict in Header as value to key 'Authorization' in python requests?

How to change the value of a key in dict in Python with its position?

How to convert list of lists to dict key value pairs python