from collections.abc import Mapping
def access_keys(dic):
print("Checking keys: ",list(dic.keys()))
if len(list(dic.keys()))==0:
print("No key found:")
return
for key , value in dic.items():
if isinstance(dic.get(key, None), Mapping):
#print(f"{key}:{value}")
new_dic = json.dumps(dic.get(key), indent=2)
print(key,new_dic)
print(f"{'_'*20}\n{'_'*20}\n")
return access_keys(dic.get(key, None))
print(f"key:{key}")
print(f"value:{value}")
else:
print("None dic got",f"{key}:{dic[key]}")
print(dic.get(key))
I want to access every key in a dic but Recursion is ending after getting an empty list of keys, I m not sure what is missing in this.
Please help me to solve this problem, also descibe me what is wrong with this code.