[Solved] How to update values in nested dictionary [closed]


There are some deeper flaws with your dictionary structure, such as values included without a key, and I would recommend reading a good tutorial on dictionary structure and reference:

https://realpython.com/python-dicts/

For your base question, though, you would treat the value in the secondary dictionary as a value of the dictionary.

Given the following dictionary (edited to be a valid dictionary, I changed the columns to a list as I believed that was your intent):

dictionary = {'table_name': 'table1', 'columns': [{'data_type': 'string', 'column_name': 'data'}, {'data_type': 'bigint','column_name': 'foreign'}]}

You would address the ‘data_type’ value in the first column of the list of columns as follows:

dictionary['columns'][0]['data_type'] = value

However, just a strictly nested dictionary given this example (only one column, so it doesn’t need to be nested in a list):

dictionary = {'table_name': 'table1', 'columns':{'data_type': 'string', 'column_name': 'data'}}

You would address the ‘data_type’ value in the columns dictionary:

dictionary['columns']['data_type'] = value

3

solved How to update values in nested dictionary [closed]