Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9, Problem 12AW
Write code that retrieves and unpickles the dictionary that you pickled in
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Suppose at some point in your code, you make a dictionary called dic1
dic1 = {'a': 1}
This dic1 dictionary will be modified later in the code. To keep track of the original version of dic1, you make another key in the same dictionary using the following assignment statement:
dic1['original'] = {'a': 1}
Later in the code you modify dic1 as follows:
dic1['b'] = 2
A colleague points out that this is equivalent to the following code:
dic2 = {'a': 1}
dic2['original'] = dic2
dic2['b'] = 2
Question 1
If you followed your colleague's suggestion and made dic2 as above, will dic2['original'] keep track of the original dictionary {'a': 1}? Explain.
Implement the following:
Given:
user_001 = {'username': 'jSmith001', 'first': 'John', 'last': 'Smith'}
1) Remove the key/value pair 'last':'Smith' from the dictionary user_001.
2) Access the values in the dictionary user_001 to print the following.
Make sure to precisely match the output format below.
Write your code in the ANSWER area provided below (must include comments if using code is not covered in the course).
Example Output
Hi John, your new login is jSmith001.
void dict_clear (dict_t* dict);
This function clears the dictionary dict, destroying each pair key/value, but does not destroy dict itself (remember that dict was allocated using dict_create, so it will need to be freed at some point, but this is not this function’s job.)
This is now the function that frees (destroys) a dictionary:
void dict_destroy (dict_t* dict);
This operates just as dict_clear, but in addition should free the memory that was allocated during dict_create. After a call to this function, if any other library function receives the pointer dict, the behavior is undefined (most likely, it will crash).
This simple function returns the current size of the dictionary:
size_t dict_size (const dict_t* dict);
Chapter 9 Solutions
Starting Out with Python (4th 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...Ch. 9 - Word Index Write a program that reads the contents...
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
- File Encryption and DecryptionWrite a program that uses a dictionary to assign “codes” to each letter of the alphabet. Forexample:codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .}Using this example, the letter A would be assigned the symbol %, the letter a would beassigned the number 9, the letter B would be assigned the symbol @, and so forth.The program should open a specified text file, read its contents, then use the dictionaryto write an encrypted version of the file’s contents to a second file. Each character in thesecond file should contain the code for the corresponding character in the first file.Write a second program that opens an encrypted file and displays its decrypted contentson the screen. in phytonarrow_forwardCode the following directions in python. 1.Assume the variable dct references a dictionary. Write an if statement that determines whether the key 'Jim' exists in the dictionary. If so, delete 'Jim' and its associated value. 2.Write code to create a set with the following integers as members: 10, 20, 30, and 40. 3.Assume each of the variables set1 and set2 references a set. Write code that creates another set containing all the elements of set1 and set2, and assigns the resulting set to the variable set3.arrow_forwardpython: def pokehelp(poke_name, stat_min): """ Question 4 - API You are looking for a Pokemon that can help you with your programming homework. Since Porygon is made of code, you decide to look into the species. Using the given API, return a dictionary that returns the name of each of Porygon's stats with a base stat GREATER THAN the given number, mapped to their value. Do not hardcode Porygon's stats into the results! It is not the only test case. Base URL: https://pokeapi.co/ Endpoint: api/v2/pokemon/{poke_name} Args: Pokemon name (str), stat minimum (int) Returns: Dictonary of stats >>> pokehelp("porygon", 65) {'defense': 70, 'special-attack': 85, 'special-defense': 75} >>> pokehelp("koraidon", 100) {'attack': 135, 'defense': 115, 'speed': 135} """ # pprint(pokehelp("porygon", 65)) # pprint(pokehelp("koraidon", 100))arrow_forward
- Task 7 Suppose you are given two dictionaries. Now create a new dictionary "marks", merging the two dictionaries, so that the original two dictionaries remain unchanged. Note: You can use dictionary functions. Given: {'Harry':15, 'Draco':8, 'Nevil":19} {'Ginie':18, 'Luna': 14} Output: {'Harry': 15, 'Draco': 8, 'Nevil": 19, 'Ginie": 18, 'Luna': 14}arrow_forwardCreat a void fuction void myUpdate(string dictionary[], int wordCount, string oldWord, string newWord); Where it will replace the oldWord with the newWord, if the search is successfularrow_forwardThis code is full of errors, what are 4 of them and how I would fix them?arrow_forward
- Create an application to keep track of a list of students and their grades in a data structures course using a binary search tree.• Create a class called student that contains 2 data members: name and grade and then create a binary search tree of objects of this class. Make sure you validate the grade (A through F, and ? for in-progress grades).• Create a menu that has the following options:o Add a student -- add the student if he/she is not already in the classo Remove a student -- display “Not Found” error message if the student is not in the class.o Update the grade -- display “Not Found” error message if the student is not in the class.o Display class roster The program should use the binary tree definition. Please list all main, cpp, and hpp files. There must be a Student class, with Student.hpp and Student.cpp files. Do not use structures.arrow_forwardLAB RESTRICTIONS, PLEASE READ:Do not add any imports, the ones that you need will be given to you.You may not use any dictionaries or dictionary methods.Do not use try-except statements, you should be able to anticipateor prevent any errors from happening at all!arrow_forwardYou will be given a dictionary, where the name of a student will be the key and a list of courses will be the value. Now, you have to take a course name as input until the user gives 'STOP' in the input. Your task is to display the list of the students taken that course after each input. Given Dictionary { 'Mike' : ['CSE110","ENG101','MAT110'], "Simon' : ['CSE111',"PHY111',"MAT110", 'CSE230], "Shawn' : ['CSE110',"ENG101',"MAT120','CSE230'], 'Alice' : ['CSE110',"ENG091','MAT092'] } Sample Input 1 CSE110 МAT110 CSE260 STOP Sample Output 1 [ 'Mike', "Shawn', 'Alice' ] [ 'Mike', "Simon'] [] Explanation 1: Mike, Shawn and Alice are doing CSE110 Mike and Simon are doing MAT110 No student is doing CSE260arrow_forward
- Task 5: Unscramble You will write a program that takes in 2 files: a dictionary file and a file listing jumbled words. Your binary will be called unscramble and will be run using unscramble The file contains a bunch of scrambled words, one word per line. Your job is to print out these jumbles words, 1 word to a line. After each jumbled word, print a list of real dictionary words that could be formed by unscrambling the jumbled word. The dictionary words that you have to choose from are in the file. As an example, the starter package contains two sample input files and the result should look as follows. The order that you display the dictionary words on each line can be different; however, the order that you print out the jumbled words should be identical to the order in your input. The sample out below is skipping a few lines to save handout space (your output must not omit these lines). nwae: wean anew wane eslyep: sleepy rpeoims: semipro imposer promise ettniner: renitent.…arrow_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_forwardIn pyhton Using the students dictionary provided below # This dictionary provided for youstudents = {'S1' : True,'S2' : False,'S3' : True,'S4' : False,} write a for loop that loops across the dictionary and collects all subject numbers (ex. 'S2') where the dictionary value is False. Imagine, for example, the dictionary indicates whether a student has completed an assignment, and we wanted to get a list of the students who had not yet completed the assignment. To answer this question, use a for loop across the students dictionary. You then need to get the associated value in each iteration, and check if it is True. If it is True, you can use continue to skip ahead to the next iteration. Otherwise, append the subject number (i.e. 'S2') to a list called incomplete.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
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