Dictionary and Frequency Tables, Checking for membershipo

https://app.dataquest.io/m/314/dictionaries-and-frequency-tables/6/checking-for-membership

if '10+' in content_ratings:
    result ="It exists"
print(result)

What I expected to happen: Nothing or error

True
False
It exists

Other details: The answer was to ask if ‘17+’ was in content ratings, since it is, I was returned the result “It exists”, but when I tested it with something that doesn’t exist (‘10+’), I still got “It exists” Why is that?

Probably you didn’t clear variable result for your test with '10+'?

Your piece of code check if '10+' exists in dictionary and since it doesn’t code skips next line but still prints variable result, which was probably assigned some value before.

if “17+” in content_ratings == True:
result = “It exists”
print(result)

Why it doesn’t work with == True ?? is this default?
When I think straight forward, I feel like it should be this way :thinking:

Even when I use
if “13+” in content_ratings == False:
result = “It exists”
print(result)
it doesn’t give me the outcome of result.

Hey there!

The in in the if statement already implies truth — in any case, the easy answer here is that it’s simply how the syntax for the in keyword was programmed for Python: https://www.w3schools.com/python/ref_keyword_in.asp

1 Like