Question
convert this python code to Lists
# 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}")
# 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}")
Answers
GPT-4o mini
To convert the given Python code that uses dictionaries into one that uses lists, we can create a list of tuples for both video games and movies. Each tuple will contain the title and its associated developer or director. Here’s how you can do it:
```python
# Creates a list of tuples for video games and their developers
games_list = [
("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 list of tuples for popular movies and their directors
movies_list = [
("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 list in a readable format
print("Video Games and their Developers:")
for game, developer in games_list:
print(f"{game} was developed by {developer}")
# Print the content of the movies list in a readable format
print("\nPopular Movies and their Directors:")
for movie, director in movies_list:
print(f"{movie} was directed by {director}")
```
### Summary of Changes Made:
- Instead of dictionaries, I created lists of tuples where each tuple consists of a game/movie title and its corresponding developer/director.
- The iteration over the data to print the information remains similar; it just accesses the items directly from the list of tuples.
```python
# Creates a list of tuples for video games and their developers
games_list = [
("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 list of tuples for popular movies and their directors
movies_list = [
("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 list in a readable format
print("Video Games and their Developers:")
for game, developer in games_list:
print(f"{game} was developed by {developer}")
# Print the content of the movies list in a readable format
print("\nPopular Movies and their Directors:")
for movie, director in movies_list:
print(f"{movie} was directed by {director}")
```
### Summary of Changes Made:
- Instead of dictionaries, I created lists of tuples where each tuple consists of a game/movie title and its corresponding developer/director.
- The iteration over the data to print the information remains similar; it just accesses the items directly from the list of tuples.