I have a dict like this:
my_dict={val1:True, val2:False, val3:False, val4:True}
How do I iterate through this dict's keys that have value False
?
Just use List comprehension
:
[key for key,val in my_dict.items() if val==False]
This will return a list
containing the keys
that have value
as False
. Now, it is a simple matter of going through the list
.
#driver values :
IN : my_dict = {'a': True,'b': False, 'c': True, 'd': False}
OUT : ['b','d']
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