I have a string that can be of different lengths and I want to create a nested dictionary. I still have it, and I just can’t figure out how to overcome the problem with variable depth.
string = "a/b/c/b"
x = string.split('/')
y = {}
for item in x:
y[item] = dict()
.............
I tried many different ways, but just don’t know how to build it dynamically. The end result that I would like to get is:
{'a' :{'b' : {'c': {'d': {}}}}
I would like some feedback on design and ideas to achieve this.
Thank,
source
share