I am trying to use the program to categorize this list of games by genre but it only seems to work if I include multiple genres in one category, struggling with the syntax. Any help?
Anonymous in /c/coding_help
127
report
```python<br># game_info<br>game_info = [<br> ('Overcooked', 'PC', 'Cooking Simulator', 4),<br> ('Overcooked2', 'PS4', 'Cooking Simulator', 4),<br> ('Overcooked2', 'Xbox', 'Cooking Simulator', 4),<br> ('Overcooked2', 'PS5', 'Cooking Simulator', 4),<br> ('Overcooked2', 'Nintendo Switch', 'Cooking Simulator', 4),<br> ('Overcooked2', 'PC', 'Cooking Simulator', 4),<br> ('Among Us', 'Mobile', 'Multiplayer', 5),<br> ('Among Us', 'PC', 'Multiplayer', 5),<br> ('Among Us', 'PS5', 'Multiplayer', 5),<br> ('Among Us', 'PS4', 'Multiplayer', 5),<br> ('Among Us', 'Xbox', 'Multiplayer', 5),<br> ('Among Us', 'Nintendo Switch', 'Multiplayer', 5),<br> ('Among Us', 'Xbox Series S/X', 'Multiplayer', 5),<br> ('Lego Games', 'PC', 'Action-Adventure', 3),<br> ('Lego Games', 'PS5', 'Action-Adventure', 3),<br> ('Lego Games', 'PS4', 'Action-Adventure', 3),<br> ('Lego Games', 'Xbox', 'Action-Adventure', 3),<br> ('Lego Games', 'Nintendo Switch', 'Action-Adventure', 3),<br> ('Lego Games', 'Xbox Series S/X', 'Action-Adventure', 3),<br> ('Minecraft', 'PC', 'Survival', 4),<br> ('Minecraft', 'PS4', 'Survival', 4),<br> ('Minecraft', 'Xbox', 'Survival', 4),<br> ('Minecraft', 'PS5', 'Survival', 4),<br> ('Minecraft', 'Nintendo Switch', 'Survival', 4),<br> ('Minecraft', 'Xbox Series S/X', 'Survival', 4),<br> ('Cuphead', 'PC', 'Run and Gun', 5),<br> ('Cuphead', 'PS4', 'Run and Gun', 5),<br> ('Cuphead', 'Xbox', 'Run and Gun', 5),<br> ('Cuphead', 'PS5', 'Run and Gun', 5),<br> ('Cuphead', 'Nintendo Switch', 'Run and Gun', 5),<br> ('Cuphead', 'Xbox Series S/X', 'Run and Gun', 5),<br> ('It Takes Two', 'PC', 'Co-op', 5),<br> ('It Takes Two', 'PS4', 'Co-op', 5),<br> ('It Takes Two', 'PS5', 'Co-op', 5),<br> ('It Takes Two', 'Xbox Series S/X', 'Co-op', 5),<br> ('It Takes Two', 'Xbox One', 'Co-op', 5),<br> ('It Takes Two', 'Nintendo Switch', 'Co-op', 5)<br>]<br><br># grouping by game genre<br>genres = {}<br>for game in game_info:<br> game_genre = game[2]<br> if game_genre not in genres:<br> genres[game_genre] = []<br> if game not in genres[game_genre]:<br> genres[game_genre].append(game)<br><br># printing the grouped games<br>for game_genre in genres:<br> print(f'\n"{game_genre}":')<br> for game in genres[game_genre]:<br> print(" -", game)<br><br> <br># printing the number of games in each genre<br>for game_genre in genres:<br> print(f"\nTotal Games for {game_genre}: {len(genres[game_genre])}")<br> <br>```
Comments (3) 6737 👁️