To begin with, never name your variables as python keywords, so don't use dict
as a python variable name, since it is replacing the python built-in keyword dict
. Instead use something like my_dict
You should consider using isinstance to check if a variable is a dictionary, instead of type
From the docs of type
:
The isinstance() built-in function is recommended for testing the type of an object, because it takes subclasses into account.
Also since you are only using values, consider only iterating on them using my_dict.values()
for v in my_dict.values():
if isinstance(v, dict):
print('This is a dictionary')