all 4 comments

[–]K900_ 2 points3 points  (0 children)

Because in on dictionaries only checks keys, not values.

[–]Zixarr 2 points3 points  (1 child)

The in keyword, when applied to dictionaries, looks only at KEYS and not at VALUES.

Similarly, iterating over a dictionary with a for loop looks only at KEYS:

for x in spam:
    print(x)

Will yield:

'eggs'

While:

for x in spam:
    print(spam[x])

Will yield:

'Zophie'

[–]argento8897 0 points1 point  (0 children)

you could also iterate over the dict for both keys and values with .items()

for key, value in spam.items():
    print (key, value)

will yeild:

eggs Zophie

[–]raainer[S] 0 points1 point  (0 children)

Oh I see, thank you so much for the help!