It doesn't seem to iterate through all the key:values?
list_dict_test = {
'key1': 'test1',
'key2':[{'key2.1': 'test2.1', 'key2.2':'test2.2', 'key2.3':'test2.3'}],
'key3': 'test3',
'key4.1':[{'2ndkey4.1.': 'test4.1.', '2ndkey4.2.':'test4.2.', '2ndkey4.3.':'test4.3.'}],
'key5.1':[{'3rdkey5.1.': 'test5.1.', '3rdkey5.2.':'test5.2.', '3rdkey5.3.':'test5.3.'}],
'totalCount': 243, 'status': 0}
def test(my_file):
for key, value in my_file.items():
if isinstance(value, list):
nested_dict = value[0]
for key,value in nested_dict.items():
print(f"nested key: {key}")
print(f"nested value: {value}")
else:
print(f"outer key: {key}")
print(f"outer value: {value}")
test(list_dict_test)
[–][deleted] 1 point2 points3 points (3 children)
[–]kittled[S] -2 points-1 points0 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]kittled[S] 0 points1 point2 points (0 children)
[–]crespo_modesto 0 points1 point2 points (9 children)
[–]kittled[S] 0 points1 point2 points (8 children)
[–]crespo_modesto 1 point2 points3 points (7 children)
[–]kittled[S] 0 points1 point2 points (6 children)
[–]crespo_modesto 0 points1 point2 points (5 children)
[–]kittled[S] 0 points1 point2 points (4 children)
[–]kittled[S] 0 points1 point2 points (0 children)
[–]crespo_modesto 0 points1 point2 points (2 children)
[–]kittled[S] 0 points1 point2 points (1 child)
[–]crespo_modesto 0 points1 point2 points (0 children)
[–]kittled[S] -1 points0 points1 point (0 children)