🐸

Lookup

Python Basicspython-basics-30-lookup
Reward: 145 XP
|

Lookup

Now that Hoppy has the spellbook, he needs to find the right spell for the situation.

You can look up a value by using its key inside square brackets [].

Casting Spells

spells = {
  "fire": "🔥",
  "water": "💧"
}

# Look up the "fire" spell
effect = spells["fire"]
print(effect) # Output: 🔥

Your Mission

1
The Library

We have a dictionary library with book locations.

2
Find It

Find the location of the "Map" and save it in a variable called location.

3
Go There

Print the location.

Suggested Solution
Click to expand

It's just like using an index in a list, but you use the key name instead of a number.

# library is predefined
location = library["Map"]
print(location)
Advanced Tips
Want more? Click to expand

If you ask for a key that doesn't exist, Python will give you a KeyError. You can use .get() to be safe!

print(spells.get("wind")) # Output: None
pymain.py
Loading...
Terminal
Terminal
Ready to run...