Bonus Exercise
Valid Dictionary Keys
Given this dictionary
Access and
print
the string "Zero"Access and
print
the string "One"Access and
print
the number 2
Wat Numbers as dictionary keys? Yup.
Another one. Given this dictionary
What will print here?:
print(is_it[2 + 2 == 4])
What will print here?:
print(is_it[4 == 2])
WAT Booleans as dictionary keys? Yup.
Read more about what key types are valid here: https://realpython.com/python-dicts/#restrictions-on-dictionary-keys
Can you use a tuple as a key? Try it and find out. Create a dictionary with a tuple as one of its keys then print its value.
Last updated
Was this helpful?