Get startedGet started for free

Dictionary Manipulation (1)

If you know how to access a dictionary, you can also assign a new value to it. To add a new key-value pair to europe you can use something like this:

europe['iceland'] = 'reykjavik'

This exercise is part of the course

Intermediate Python

View Course

Exercise instructions

  • Add the key 'italy' with the value 'rome' to europe.
  • To assert that 'italy' is now a key in europe, print out 'italy' in europe.
  • Add another key:value pair to europe: 'poland' is the key, 'warsaw' is the corresponding value.
  • Print out europe.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Definition of dictionary
europe = {'spain':'madrid', 'france':'paris', 'germany':'berlin', 'norway':'oslo' }

# Add italy to europe


# Print out italy in europe


# Add poland to europe


# Print europe
Edit and Run Code