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, Problem 3MC
The ________ function returns the number of elements in a dictionary:
a. size()
b. len()
C. elements()
d. count()
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:26
Students have asked these similar questions
Data 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'}…
Given an alphanumeric list, separate it into three different lists stored in a dictionary:
• The first list should only contain lowercase letters.
• The second list should only contain uppercase letters.
•
The third list should only contain numbers.
Each list stored in the dictionary should be stored in ascending order. Use the following naming
convention when creating your lists:
• numbers.
• uppercase
• lowercase
Make sure that you adhere to the above instruction, as the name of your lists will be used to mark
your function.
Arguments:
• character_list: (list) → list of alphanumeric characters.
Return:
dictionary (dict) → dictionary containing all three lists.
In [ ]: ### START FUNCTION
def create_dictionary (character_list):
# Your code here.
return dictionary
### END FUNCTION
In [ ]: 1st = [2, 'j','K','o',6, 'x',5,'A',3.2]
create_dictionary (1st)
Data structures
dict_from_string(dict_str:str)->dict
This function will be given a single parameter, a string representing a dictionary. Your job is to convert the string into an actual dictionary and return the dictionary. Make sure all key-value pairs in the string exist in the newly created dictionary. The string will contain only numbers or single letters as key values pairs. Make sure all letters are kept as strings and all numbers are converted to integers in the newly created dictionary.
Example:
String Input: '{9: 'V', 'G': 0, 'M': 9, 'u': 3, 2: 'o', 8: 'u', 'q': 9, 'D': 1}'
Expected: {9: 'V', 'G': 0, 'M': 9, 'u': 3, 2: 'o', 8: 'u', 'q': 9, 'D': 1}
String Input: '{10: 'D', 1: 'Z', 5: 'a'}'
Expected: {10: 'D', 1: 'Z', 5: 'a'}
String Input: '{'M': 2, 'V': 0, 3: 'x', 6: 'J', 5: 'J', 7: 'T', 8: 'P', 4: 'q', 1: 'h'}'
Expected: {'M': 2, 'V': 0, 3: 'x', 6: 'J', 5: 'J', 7: 'T', 8: 'P', 4: 'q', 1: 'h'}
String Input: '{3: 'D', 10: 'T', 7: 'm', 'u': 9, 't': 5, 6: 'Z', 'H': 10, 'B':…
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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The following program will compile and run, but it uses poor programming style. Modify the program so that it u...
Absolute Java (6th Edition)
Figure 1-30 shows the Visual Studio IDE. What are the names of the four areas indicated in the figure? Figure 1...
Starting Out With Visual Basic (7th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
The following program skeleton determines whether a person qualifies for a credit card. To qualify, the person ...
Starting Out with C++ from Control Structures to Objects (8th Edition)
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (8th Edition)
Is it possible to remove the else part of the if-statement in the printTicket method (i.e., remove the word els...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
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
- Assume 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_forwardData 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_forwardPythonarrow_forward
- Assume 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_forwardExercise: 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_forwardPython program named "YourMuseumID_Exhibits.py" focusing on museum exhibit data: You have a list of dictionaries representing exhibits in a museum. Each dictionary contains the exhibit name, the number of artifacts on display, and the historical era it covers. Perform the following tasks: (a) Calculate and display the total number of artifacts on display for all exhibits in the museum. (b) Identify and display the exhibit with the highest number of artifacts on display. (c) Implement a function that takes a user-input exhibit name and searches for it in the list. If found, display the number of artifacts on display and the historical era it covers; if not found, print a message indicating that the exhibit is not in the museum. (d) Implement a sorting algorithm of your choice to sort the exhibits based on the number of artifacts on display in descending order and display the sorted list. Make sure to incorporate functions for each task and display the results in the main function with…arrow_forward
- The get(key) function for a dictionary will return _____ if the key does not exist. In python. A. “ B. {} C. “Null” D. None arrow_forwardOverview This program will have you use a loop to prompt a user for three games and their systems and then store them in a dictionary called games_dict). Then it will ask the user for the worst game, delete that game, and print out the contents of the revised games_dict. Expected Output Example 1 What is a great game? Mario What system can I play that on? Nintendo What is a great game? Sonic I play that on? Sega What system can What is a great game? Spyro What system can I play that on? layStation That's too many, let's get rid of one What game should we remove? Sonic The new dictionary is: You can play Mario on Nintendo You can play Spyro on PlayStation Specifications • You should submit a single file called M4A3.py • It should follow the submission standards outlined here: Submission Standards • Your program should start by defining an empty dictionary called games_dict • It should populate games_dict using a for-loop • It should print out games_dict using a for-loop. Tips and Tricks…arrow_forwardHomework Assignment-1Topics: Functions, Dictionary, ImportProblem description: Write a python application to simulate an online clothing system. Thepurpose of this assignment is to gain experience in Python dictionary structure, create basicPython functions and import a module.Design solution: The template file contains a list of clothes item sold, each item in the listcontains the item id, name of the item and the prices. The program will generate an items_dictwhere each key is the item id of the cloth and the values will be a list of item name and priceinformation. A customer will be presented with a main menu with 4 different options: displayall items, add an item to cart, checkout and exit the program. A customer can buy an item byentering the ID of the item. This program implements a dictionary called cart, where each key isthe item id and the values are the list of name, price and quantity that user chooses topurchase. The program keeps repeating by displaying the main menu to…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Dictionaries - Introduction to Data Structures (Episode 8); Author: NullPointer Exception;https://www.youtube.com/watch?v=j0cPnbtp1_w;License: Standard YouTube License, CC-BY