Question: Please Solve in Python You want to have a list of nicknames for each state, therefore you decided to use a dictionary data structure to

Please Solve in Python

You want to have a list of nicknames for each state, therefore you decided to use a dictionary data structure to store this data. Write a function that takes a list of tuples (the output from the previous question, i.e. a list of (, ) tuples) and converts it to a dictionary, where keys are states and values are a list of nicknames associated with that state. Return an empty dictionary if no tuples are provided.

Notes: You can assume that there aren't duplicate nicknames. You can treat NO STATE PROVIDED as a state name and place that in the dictionary as well.

def dict_of_states(tuples): """ >>> dict_of_states([('AL', 'Cotton State'), ... ('LA', 'Pelican State'), ('LA', 'Creole State'), ... ('AL', 'Yellowhammer State'), ('LA', 'Sugar State'), ... ('MS', 'Magnolia State')]) {'AL': ['Cotton State', 'Yellowhammer State'], \ 'LA': ['Pelican State', 'Creole State', 'Sugar State'], \ 'MS': ['Magnolia State']}

>>> dict_of_states([('MO', 'Show Me State'), ... ('NY', 'Empire State'), ('NO STATE PROVIDED', 'Lone Star State')]) {'MO': ['Show Me State'], 'NY': ['Empire State'], \ 'NO STATE PROVIDED': ['Lone Star State']} >>> dict_of_states([('NO STATE PROVIDED', 'Granite State'), \ ('NO STATE PROVIDED', 'Sooner State')]) {'NO STATE PROVIDED': ['Granite State', 'Sooner State']} """

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!