Oct-16-2019, 11:54 PM
Hi!
I thought that checking if a certain 'x' element existed in a certain dictionary named, let's say 'mixedBag' would check if that 'x' element is in that dictionary, being either a 'key', either a 'value' in it, but it seems that it is not the case.
I'll explain my doubt with an example in IDLE:
Am I missing something? Because I can see clearly that 89 is indeed in the dictionary famousActors, something that is later corroborated when I check for 89 in the values of the dictionary famousActors, returning the Boolean value of
Thanks and all the best,
I thought that checking if a certain 'x' element existed in a certain dictionary named, let's say 'mixedBag' would check if that 'x' element is in that dictionary, being either a 'key', either a 'value' in it, but it seems that it is not the case.
I'll explain my doubt with an example in IDLE:
Output:>>> famousActors = {'Clint Eastwood': 89, 'Robert Redford': 83, 'Sigourney Weaver': 70, 'Glenn Close': 72}
>>> 'Clint Eastwood' in famousActors
True
>>> 'Clint Eastwood' in famousActors.keys()
True
>>> 'Clint Eastwood' in famousActors.values()
False
>>> 89 in famousActors
False
>>> 89 in famousActors.keys()
False
>>> 89 in famousActors.values()
True
>>>
Where you can see, that if I check for 'Clint Eastwood' in the dictionary famousActors, or for 'Clint Eastwood' in the keys of the dictionary famousActors, both return the Boolean value of True
(as I expected), but when I check for 89 in the dictionary famousActors, it returns the Boolean value of False
(something that I was not expecting at all).Am I missing something? Because I can see clearly that 89 is indeed in the dictionary famousActors, something that is later corroborated when I check for 89 in the values of the dictionary famousActors, returning the Boolean value of
True
(as I expected).Thanks and all the best,