• JUPYTER
  • FAQ
  • View as Code
  • Python 3 Kernel
  • View on GitHub
  • Execute on Binder
  • Download Notebook
  1. learn-python3
  2. notebooks
  3. beginner
  4. exercises

1. Populating a dictionary¶

Create a dictionary by using all the given variables.

In [ ]:
first_name = "John"
last_name = "Doe"
favorite_hobby = "Python"
sports_hobby = "gym"
age = 82
In [ ]:
# Your implementation
my_dict = 
In [ ]:
assert my_dict == {"name": "John Doe", "age": 82, "hobbies": ["Python", "gym"]}

2. Accessing and merging dictionaries¶

Combine dict1, dict2, and dict3 into my_dict. In addition, get the value of special_key from my_dict into a special_value variable. Note that original dictionaries should stay untouched and special_key should be removed from my_dict.

In [ ]:
dict1 = dict(key1="This is not that hard", key2="Python is still cool")
dict2 = {"key1": 123, "special_key": "secret"}
# This is also a away to initialize a dict (list of tuples)
dict3 = dict([("key2", 456), ("keyX", "X")])
In [ ]:
# 'Your impelementation'
my_dict = 
special_value = 
In [ ]:
assert my_dict == {"key1": 123, "key2": 456, "keyX": "X"}
assert special_value == "secret"

# Let's check that the originals are untouched
assert dict1 == {"key1": "This is not that hard", "key2": "Python is still cool"}
assert dict2 == {"key1": 123, "special_key": "secret"}
assert dict3 == {"key2": 456, "keyX": "X"}

This website does not host notebooks, it only renders notebooks available on other websites.

Delivered by Fastly, Rendered by OVHcloud

nbviewer GitHub repository.

nbviewer version: 8b013f7

nbconvert version: 7.2.3

Rendered (Tue, 10 Jun 2025 07:09:03 UTC)