I have an array ['a', 'b', 'c']
, and I want to create a nested object like below.
{ a: {
b : {
c: {}
}
}
I have an array ['a', 'b', 'c']
, and I want to create a nested object like below.
{ a: {
b : {
c: {}
}
}
How about like this? I implement it as Dictionary
base = ["a", "b", "c"]
result = {}
for b in base[::-1]:
result = {b: result}
print(result)
# {'a': {'b': {'c': {}}}}