Linked Questions
12 questions linked to/from Setting a value in a nested Python dictionary given a list of indices and value
0
votes
1
answer
139
views
Writing a value into a Nested Dictionary and specifying path using a List [duplicate]
I need to update the value in a nested dictionary, however I have a list with all of the keys that I need to go through in order to get tot hat value. However this list is automatically generated and ...
0
votes
0
answers
188
views
Create a single dictionary of nested dictionaries from *multiple* dot notation strings [duplicate]
I have a number of dot notation strings and their values that I want to use to create a dictionary of dictionaries, but I'm stuck...
For example, I have these strings:
tagPaths = []
tagPaths.append(&...
0
votes
0
answers
47
views
Python 2.7 create a dictionary from dotted values [duplicate]
How can I achieve the same thing in Python 2? I don't believe dotty_dict works in python 2.7 whereas it will in python 3.
from dotty_dict import dotty
dot = dotty()
alist = ['a.b.c.d.e.f.g.h.i', 'a....
222
votes
22
answers
197k
views
Access nested dictionary items via a list of keys?
I have a complex dictionary structure which I would like to access via a list of keys to address the correct item.
dataDict = {
"a":{
"r": 1,
"s": 2,
...
165
votes
21
answers
169k
views
Elegant way to check if a nested key exists in a dict?
Is there are more readable way to check if a key buried in a dict exists without checking each level independently?
Lets say I need to get this value in a object buried (example taken from Wikidata):
...
12
votes
3
answers
7k
views
Set nested dict value and create intermediate keys
I feel like I saw a way to do this recently. Say I've got an empty dict and I want to set a value in a nested dict inside that empty dict, but obviously that nested dict hasn't been created yet. Is ...
-3
votes
2
answers
2k
views
Split string list into dictionary keys in python
I have a string 'request.context.user_id' and I want to split the string by '.' and use each element in the list as a dictionary key. Is there a way to do this for lists of varying lengths without ...
0
votes
2
answers
122
views
How do I insert new items in a blank dictionary in Python 3?
I have a dictionary as follows:
mydict = {'HEALTH': {'NumberOfTimes': 2, 'Score': 12},
'branch': {'NumberOfTimes': 4, 'Score': 34},
'transfer': {'NumberOfTimes': 1, 'Score': 5},
'deal': {'...
0
votes
0
answers
191
views
Create multidimensional dictionary from list elements [duplicate]
I have list of elements like a=[0,1,2,3], I want to convert these list elements into multidimensional dictionary a[0][1][2][3] is it possible using python.
i.e input a=[0,1,2,3] and desired output a[...
0
votes
1
answer
129
views
Update value within nested dict of arbitrary depth without changing the rest of the dict in Python
So I have a nested dictionary in Python:
{'entry': {'definition': 'str',
'endTime': 'str',
'entryID': {'identifierType': 'str', 'identifierValue': 'str'},
'instrument': {'FIB': {'...
-1
votes
1
answer
88
views
Create nested defaultdict in Python
I'm trying to create a nested dictionary in Python so that, given a list of strings, the dictionary records the number of occurrences of that string order.
For example, if the string list is:
["...
0
votes
0
answers
46
views
Why are multiple values incorrectly updated in my dynamically created nested dicts?
Dfs is a dict with dataframes and the keys are named like this: 'datav1_135_gl_b17'
We would like to calculate a matrix with constants. It should be possible to assign the values in the matrix ...