The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Microsoft Word - CS 1301 – Homework 5.docx
Python Programming QuestionÂ
Â
Function Name: updateNetworks (20 points)
Description: Define a function that takes in a dictionary and a list of tuples as parameters. The dictionary maps networks to a list of TV shows on that network. Each of the tuples contains a network and a TV show. Your function should update the networks dictionary using the tuples according to the following guidelines. If the network in the tuple is not in the dictionary, then you should add it to your dictionary with the value being a list of that networks’ TV show. If your network is in the dictionary, then if the TV show is not in that networks’ list of TV shows, then it needs to add the TV show to the list of TV shows for that corresponding
CS 1301 – Homework 5: Tuple and Dictionary Manipulation – Fall 2016
Â
network. Otherwise, if your network is in your dictionary and the TV show is in that networks’ list of TV shows, then you should delete that TV show from the list of networks. You will then return the updated dictionary.
Parameter(s):
1. A dictionary. The keys are strings and the values are lists of strings. The list may be empty.
a. Thekeysarethenetworks.
b. The values are the corresponding networks’ TV shows. 2. A list of tuples. Each tuple has two elements, both strings.
a. Thefirstelementofeachtupleisanetwork
b. The second element of each tuple is a TV show.
Return Value: The original dictionary with the updated values.
Example(s):
>>> networks = {"Netflix": ["Daredevil"], "ABC": [],
"CBS": ["The Big Bang Theory", "Two and a Half Men"], "NBC": ["30 Rock", "Parks and Recreation", "The Office"], "HBO": ["Last Week Tonight"]}
>>> tv_shows = [("Netflix", "Luke Cage"), ("Netflix", "Stranger Things"), ("The CW", "Jane the Virgin"), ("CBS", "Two and a Half Men"), ("ABC", "Fresh Off the Boat"), ("NBC", "Parks and Recreation"), ("NBC", "The Office"), ("NBC", "30 Rock"),
("The CW", "Pretty Little Liars")]
>>> print(updateNetworks(networks, tv_shows))
{'The CW': ['Jane the Virgin', 'Pretty Little Liars'], 'ABC': ['Fresh Off the Boat'], 'HBO': ['Last Week Tonight'], 'CBS': ['The Big Bang Theory'], 'Netflix': ['Daredevil', 'Luke Cage', 'Stranger Things'], 'NBC': []}
-----------