Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

=+19.2. (a) Show that L"((0, 1], , A) is not separable.

Answered: 1 week ago