How to check if a variable is a dictionary in python

This question already has an answer here:


ANSWERS:


You could use if type(ele) is dict or use isinstance(ele, dict) which would work if you had subclassed dict:

d = {'abc':'abc','def':{'ghi':'ghi','jkl':'jkl'}}
for ele in d.values():
    if isinstance(ele,dict):
       for k, v in ele.items():
           print(k,' ',v)


 MORE:


 ? How to check if a variable is a dictionary in python
 ? How to check if a variable is a dictionary in python
 ? Differences between isinstance() and type() in python
 ? Get path of all the elements in dictionary
 ? How to check if two instances are of the same class Python
 ? How to check if two instances are of the same class Python
 ? How to check if two instances are of the same class Python
 ? How to check if two instances are of the same class Python
 ? Is there a way to check if two object contain the same values in each of their variables in python?
 ? How do I see what the "type" of an object is, in Python?