Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9.1, Problem 7CP
Suppose a dictionary named inventory exists. What does the following statement do?
del inventory[654]
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Exercise: Check Monster Character Exists
Description
In this series of exercises, you will create functions
to create, modify and examine dictionaries that
represent characters in an animated film, and the
cast members who voice the characters. The
keys of the dictionary will be character names.
The values in the dictionary will be voice actor
names.
For this exercise, you will create a function that
checks if a character is already in the dictionary.
Files
monsterfunctions.py : set of functions to work with monster cast dictionaries.
Function Name
has_character
Parameters
monsters: a dictionary
character: a string, the name of a character
Action
Checks if character is a key in monsters.
Return Value
True if character is a key in monsters, otherwise False.
Examples
monsters = create_monster_cast()
monsters = add_cast_member(monsters, "Mike", "William Crystal")
has_character(monsters, "Mike") -> True
has_character(monsters, "Sully") -> False
Exercise: Check Monster Character Exists
Description
In this series of exercises, you will create functions
to create, modify and examine dictionaries that
represent characters in an animated film, and the
cast members who voice the characters. The
keys of the dictionary will be character names.
The values in the dictionary will be voice actor
names.
For this exercise, you will create a function that
checks if a character is already in the dictionary.
Files
monsterfunctions.py : set of functions to work with monster cast dictionaries.
Function Name
has_character
Parameters
monsters: a dictionary
character: a string, the name of a character
Action
Checks if character is a key in monsters.
Return Value
True if character is a key in monsters, otherwise False.
Examples
monsters = create_monster_cast()
monsters = add_cast_member(monsters, "Mike", "William Crystal")
has_character(monsters, "Mike") -> True
has_character(monsters, "Sully") -> False
Exercise: Check Monster Character Exists
Description
In this series of exercises, you will create functions
to create, modify and examine dictionaries that
represent characters in an animated film, and the
cast members who voice the characters. The
keys of the dictionary will be character names.
The values in the dictionary will be voice actor
names.
For this exercise, you will create a function that
checks if a character is already in the dictionary.
Files
monsterfunctions.py : set of functions to work with monster cast dictionaries.
Function Name
has_character
Parameters
monsters: a dictionary
character: a string, the name of a character
Action
Checks if character is a key in monsters.
Return Value
True if character is a key in monsters, otherwise False.
Examples
monsters = create_monster_cast()
monsters = add_cast_member(monsters, "Mike", "William Crystal")
has_character(monsters, "Mike") -> True
has_character(monsters, "Sully") -> False
Chapter 9 Solutions
Starting Out with Python (3rd Edition)
Ch. 9.1 - An element in a dictionary has two parts. What are...Ch. 9.1 - Which part of a dictionary element must be...Ch. 9.1 - Suppose ' start' : 1472 is an element in a...Ch. 9.1 - Suppose a dictionary named employee has been...Ch. 9.1 - What will the following code display? stuff = {1 :...Ch. 9.1 - Prob. 6CPCh. 9.1 - Suppose a dictionary named inventory exists. What...Ch. 9.1 - What will the following code display? stuff = {1 :...Ch. 9.1 - What will the following code display? stuff = {1 :...Ch. 9.1 - What is the difference between the dictionary...
Ch. 9.1 - Prob. 11CPCh. 9.1 - Prob. 12CPCh. 9.1 - What does the values method return?Ch. 9.2 - Prob. 14CPCh. 9.2 - Prob. 15CPCh. 9.2 - Prob. 16CPCh. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - Prob. 22CPCh. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - Prob. 25CPCh. 9.2 - Prob. 26CPCh. 9.2 - After the following code executes, what elements...Ch. 9.2 - Prob. 28CPCh. 9.2 - After the following code executes, what elements...Ch. 9.2 - After the following code executes, what elements...Ch. 9.2 - After the following code executes, what elements...Ch. 9.2 - Prob. 32CPCh. 9.3 - Prob. 33CPCh. 9.3 - When you open a file for the purpose of saving a...Ch. 9.3 - When you open a file for the purpose of retrieving...Ch. 9.3 - Prob. 36CPCh. 9.3 - Prob. 37CPCh. 9.3 - Prob. 38CPCh. 9 - You can use the __________ operator to determine...Ch. 9 - You use ________ to delete an element from a...Ch. 9 - The ________ function returns the number of...Ch. 9 - You can use_________ to create an empty...Ch. 9 - The _______ method returns a randomly selected...Ch. 9 - The __________ method returns the value associated...Ch. 9 - The __________ dictionary method returns the value...Ch. 9 - The ________ method returns all of a dictionary's...Ch. 9 - The following function returns the number of...Ch. 9 - Prob. 10MCCh. 9 - Prob. 11MCCh. 9 - This set method removes an element, but does not...Ch. 9 - Prob. 13MCCh. 9 - Prob. 14MCCh. 9 - This operator can be used to find the difference...Ch. 9 - Prob. 16MCCh. 9 - Prob. 17MCCh. 9 - The keys in a dictionary must be mutable objects.Ch. 9 - Dictionaries are not sequences.Ch. 9 - Prob. 3TFCh. 9 - Prob. 4TFCh. 9 - The dictionary method popitem does not raise an...Ch. 9 - The following statement creates an empty...Ch. 9 - Prob. 7TFCh. 9 - Prob. 8TFCh. 9 - Prob. 9TFCh. 9 - Prob. 10TFCh. 9 - What will the following code display? dct =...Ch. 9 - What will the following code display? dct =...Ch. 9 - What will the following code display? dct =...Ch. 9 - What will the following code display? stuff =...Ch. 9 - How do you delete an element from a dictionary?Ch. 9 - How do you determine the number of elements that...Ch. 9 - Prob. 7SACh. 9 - What values will the following code display? (Dont...Ch. 9 - After the following statement executes, what...Ch. 9 - After the following statement executes, what...Ch. 9 - After the following statement executes, what...Ch. 9 - After the following statement executes, what...Ch. 9 - After the following statement executes, what...Ch. 9 - What will the following code display? myset =...Ch. 9 - After the following code executes, what elements...Ch. 9 - Prob. 16SACh. 9 - Prob. 17SACh. 9 - Prob. 18SACh. 9 - After the following code executes, what elements...Ch. 9 - Prob. 20SACh. 9 - Write a statement that creates a dictionary...Ch. 9 - Write a statement that creates an empty...Ch. 9 - Assume the variable dct references a dictionary....Ch. 9 - Assume the variable dct references a dictionary....Ch. 9 - Prob. 5AWCh. 9 - Prob. 6AWCh. 9 - Prob. 7AWCh. 9 - Prob. 8AWCh. 9 - Prob. 9AWCh. 9 - Prob. 10AWCh. 9 - Assume the variable dct references a dictionary....Ch. 9 - Write code that retrieves and unpickles the...Ch. 9 - Course information Write a program that creates a...Ch. 9 - Capital Quiz The Capital Quiz Problem Write a...Ch. 9 - File Encryption and Decryption Write a program...Ch. 9 - Unique Words Write a program that opens a...Ch. 9 - Prob. 5PECh. 9 - File Analysis Write a program that reads the...Ch. 9 - World Series Winners In this chapters source code...Ch. 9 - Name and Email Addresses Write a program that...Ch. 9 - Blackjack Simulation Previously in this chapter...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Exercise: Check Monster Character Exists Description In this series of exercises, you will create functionsto create, modify and examine dictionaries thatrepresent characters in an animated film, and thecast members who voice the characters. Thekeys of the dictionary will be character names.The values in the dictionary will be voice actornames. For this exercise, you will create a function thatchecks if a character is already in the dictionary. Files • monsterfunctions.py : set of functions to work with monster cast dictionaries. Function Name has_character Parameters • monsters: a dictionary • character: a string, the name of a character Action Checks if character is a key in monsters. Return Value True if character is a key in monsters, otherwise False. Examples monsters = create_monster_cast()monsters = add_cast_member(monsters, "Mike", "William Crystal")has_character(monsters, "Mike") -> Truehas_character(monsters, "Sully") -> Falsearrow_forwardSuppose a dictionary named employee has been created. What does the following statement do?employee['id'] = 54321arrow_forwardExercise: Least Dictionary Value Description In this exercise you will find the value in a dictionary with the least value. Least means that the value is less than or equal to all other values in the dictionary. Remember that the 2 Assistant Object inspectorarrow_forward
- Assume the variable definitions references a dictionary. Write an if statement that determines whether the key 'marsupial' exists in the dictionary. If so, delete 'marsupial' and its associated value. If the key is not in the dictionary, display a message indicating so.arrow_forwardData structures unique_values(a_dict:dict)-> dict This function will receive a single dictionary parameter known as a_dict. a_dict will contain a single letter as a string and numbers as values. This function is supposed to search a_dict to find all values that appear only once in the a_dict. The function will create another dictionary named to_ret. For all values that appear once in a_dict the function will add the value as a key in to_ret and set the value of the key to the key of the value in a_dict (swap the key-value pairs, since a_dict contains letters to numbers, to_ret will contain Numbers to Letters). Finally, the function should return to_ret. Example: a_dict: {'X': 2, 'Y': 5, 'N': 2, 'L': 2, 'W': 1, 'G': 0, 'R': 1} Expected: {5: 'Y', 0: 'G'} a_dict: {'Z': 3, 'P': 3, 'E': 2, 'G': 0, 'T': 5, 'L': 1, 'Q': 0} to_ret: {2: 'E', 5: 'T', 1: 'L'} a_dict: {'E': 3, 'X': 3} to_ret: {} a_dict: {'G': 3, 'D': 3, 'C': 4, 'Q': 1, 'H': 1, 'M': 2, 'Z': 1, 'W': 3} to_ret: {4: 'C', 2: 'M'}…arrow_forwardThe following statement creates an empty dictionary: mydct = {} True or Falsearrow_forward
- Code the following directions in python: 1.Write a statement that creates a dictionary containing the following key-value pairs: 'a' : 1 'b' : 2 'c' : 3 2.Write a statement that creates an empty dictionary. 3.Assume the variable dct references a dictionary. Write an if statement that determines whether the key 'James' exists in the dictionary. If so, display the value that is associated with that key. If the key is not in the dictionary, display a message indicating so.arrow_forwardAssume the variable dct references a dictionary. Write an if statement that determines whetherthe key 'James' exists in the dictionary. If so, display the value that is associated with that key.If the key is not in the dictionary, display a message indicating so.arrow_forwardFind Country Function Name: findCountry() Parameters: capitalList ( list ) Returns: Dictionary mapping each capital to its country( dict ) Description: Given a list of countries' capital cities, write a function that returns a dictionary that maps a capital to its country's name. Note: Assume that all capital cities provided are valid. example test cases: >>> findCountry(('tokyo', 'delhi', 'stockholm']) {'tokyo': 'Japan', 'delhi": 'India', 'stockholm': 'Sweden'} >>> findCountry(l'paris', 'canberra', 'copenhagen']) {'paris': 'France', 'canberra': 'Australia', 'copenhagen': 'Denmark'} For this assignment, use the REST countries API (https://restcountries.com/#api-endpoints-v2). For all of your requests, make sure you to use version 2 of the REST countries API (V2), not version 3 (V3.1). If you make a request with the URL: https://restcountries.com/v2/alpha/usa, you will receive the following response: { "name": "United States of America", "topLevelDomain": [".us"], "alpha2Code": "US",…arrow_forward
- Data structures concatenate_dict(dict_list:list)->dict This function will be given a single parameter known as the Dictionary List. Your job is to combine all the dictionaries found in the dictionary list into a single dictionary and return it. There are two rules for adding values to the dictionary: 1. You must add key-value pairs to the dictionary in the same order they are found in the Dictionary List. 2. If the key already exists, it cannot be overwritten. In other words, if two or more dictionaries have the same key, the key to be added cannot be overwritten by the subsequent dictionaries. Example: Dictionary List: [{'Z': 6, 'k': 10, 'w': 3, 'I': 8, 'Y': 5}, {'Y': 1, 'Z': 4}, {'X': 2, 'L': 5}] Expected: {'Z': 6, 'k': 10, 'w': 3, 'I': 8, 'Y': 5, 'X': 2, 'L': 5} Dictionary List: [{'z': 0}, {'z': 7}] Expected: {'z': 0} Dictionary List: [{'b': 7}, {'b': 10, 'A': 8, 'Z': 2, 'V': 1}] Expected: {'b': 7, 'A': 8, 'Z': 2, 'V': 1}arrow_forwardAssume the following list exists: names = ['Chris', 'Katie', 'Joanne', 'Kurt'] Write a statement that uses a dictionary comprehension to create a dictionary named X in which each element contains the length of a name from the list as the key, and the corresponding name's initial character as its value.arrow_forwardProblem The program takes a dictionary and checks if a giver. key exists in a dictionary or not.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Dictionaries - Introduction to Data Structures (Episode 8); Author: NullPointer Exception;https://www.youtube.com/watch?v=j0cPnbtp1_w;License: Standard YouTube License, CC-BY