Question
Language: Python Topic: Dictionaries Function name : trip_planner Parameters : list of tuples Returns: dictionary with each value as a dictionary Description: You and your
Language: Python
Topic: Dictionaries
Function name : trip_planner Parameters : list of tuples Returns: dictionary with each value as a dictionary
Description: You and your friends are planning a trip to NYC! In preparation, you guys make a list together of things you want to do when you get to NYC, except its a little bit disorganized with a lot of duplicate activities. Your job is to organize the list into a more accessible dictionary.
Each element in the input list is a tuple containing the category (string), name (string), and cost (int) of the activity. The output dictionary should arrange the activities first by using their category a s keys. The assigned value of each category should be another dictionary that maps each corresponding activity name to its associated cost. If there are duplicate activities with the same category and name, their costs should all be added together.
>>> list1 = [('show', 'Shawn Mendes: the Concert', 100), ('food', 'Levain Bakery', 10000), ('sightseeing', 'Statue of Liberty', 0), ('show', 'Hamilton', 20), ('sightseeing', 'Brooklyn Bridge', 10), ('show', 'Hamilton', 70), ('food', 'Halal Guys', 5), ('show', 'Shawn Mendes: the Concert', 200)] >>> print(trip_planner(list1)) {'show': {'Shawn Mendes: the Concert': 300, 'Hamilton': 90}, 'food': {'Levain Bakery': 10000, 'Halal Guys': 5}, 'sightseeing': {'Statue of Liberty': 0, 'Brooklyn Bridge': 10}}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started