Sure! Below is an example of a Python script that creates two dictionaries: one for video games and their developers, and another for popular movies and their directors. Each dictionary contains at least 10 keys (video games or movies) and their corresponding values (developers or directors). I've also included comments to explain what each part of the code does.
# Creates a dictionary for video games and their developers
games_dictionary = {
"The Legend of Zelda: Breath of the Wild": "Nintendo",
"The Witcher 3: Wild Hunt": "CD Projekt Red",
"Dark Souls": "FromSoftware",
"God of War": "Santa Monica Studio",
"Minecraft": "Mojang Studios",
"Fortnite": "Epic Games",
"Red Dead Redemption 2": "Rockstar Games",
"Hollow Knight": "Team Cherry",
"Overwatch": "Blizzard Entertainment",
"Celeste": "Maddy Makes Games"
}
# Creates a dictionary for popular movies and their directors
movies_dictionary = {
"Inception": "Christopher Nolan",
"The Shawshank Redemption": "Frank Darabont",
"Pulp Fiction": "Quentin Tarantino",
"The Godfather": "Francis Ford Coppola",
"The Dark Knight": "Christopher Nolan",
"Schindler's List": "Steven Spielberg",
"Fight Club": "David Fincher",
"Forrest Gump": "Robert Zemeckis",
"The Matrix": "Lana and Lilly Wachowski",
"Parasite": "Bong Joon-ho"
}
# Print the content of the games dictionary in a readable format
print("Video Games and their Developers:")
for game, developer in games_dictionary.items():
print(f"{game} was developed by {developer}")
# Print the content of the movies dictionary in a readable format
print("\nPopular Movies and their Directors:")
for movie, director in movies_dictionary.items():
print(f"{movie} was directed by {director}")
Explanation of the Code
-
Dictionary Creation:
- We create two dictionaries named
games_dictionary
andmovies_dictionary
. Each dictionary contains key-value pairs where the key is the name of a game or movie, and the value is its developer or director, respectively.
- We create two dictionaries named
-
Comments:
- There are comments throughout the code explaining the purpose of each section, making it easier for anyone reading the code to understand its functionality.
-
Looping through Dictionaries:
- We use a
for
loop to iterate over each dictionary. Theitems()
method returns key-value pairs, which we unpack into the variablesgame
anddeveloper
ormovie
anddirector
.
- We use a
-
Formatted Output:
- In the print statements inside the loops, we use formatted string literals (f-strings) to neatly output the information in a reader-friendly way.
You can run this script in your Python environment to see the output, which will list the games with their developers and the movies with their directors in a clear format.