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'
Diese Übung ist Teil des Kurses
Intermediate Python
Anleitung zur Übung
- Add the key
'italy'with the value'rome'toeurope. - To assert that
'italy'is now a key ineurope, print out'italy' in europe. - Add another key:value pair to
europe:'poland'is the key,'warsaw'is the corresponding value. - Print out
europe.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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