nested = {'X': {'a': {'one': 10, 'two': 20}, 'b': {'one': 10, 'two': 20},
'Y': {'a': {'one': 10, 'two': 20}, 'b': {'one': 10, 'two': 20}}}
This dict value is
nested = {'X_a_one':10, 'X_a_two':20...}
I'm going to make it flat.
I tried as below, but my head is not working in the middle.
def flat_dict(dup_dict):
result = {}
for k, v in dup_dict.items():
if type(v) is dict:
for k1, v1 in v.items():
if type(v1) is dict:
key = k+k1
value = v1
for k2, v2 in v1.items():
print(k2, v2)
print("key:", k+k1+k2, "/value:", v2 )
else:
result[k] = v
# # if type(v) is dict:
# # _flat_dict_rec(k, v, result)
return
© 2024 OneMinuteCode. All rights reserved.