DON'T FORGET, SEE MY SELF-ANSWER BELOW
Let's say i have a dictionary called d:
d = {'a': {1: (1,2,3), 2: (4,5,6)},'b': {1: (3,2,1), 2: (6,5,4)}}
As you can see, it is a nested dictionary, how would i detect if it is?
Here are some examples:
d = {'a':{1:(1,2,3),2:(4,5,6)},'b':{1:(3,2,1),2:(6,5,4)}}
d = {'a':1,'b':2}
I want the output:
True
False
P.S. list of dictionaries don't count.
Use any:
print(any(isinstance(i,dict) for i in d.values()))
First dictionary will return:
True
Second will:
False
To explain:
Go and iterate trough d's values.
Use isinstance to check whether if the type is dict or not.
Use an outer any to check if there are any elements that are True (are dictionaries).
There you go now, it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With