Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 9, Problem 4TF

Explanation of Solution

Dictionary keys cannot be list:

  • • In Python, a dictionary is defined as an unordered collection of data.
  • • Each element of the dictionary is a key-value pair.
  • • For each key, there is a value mapped to it.
  • • The keys in dictionary cannot be modified but the values can be modified.
  • • Keys in the dictionary must be immutable objects.
    • ○ Immutable object:
      • ■ An object that cannot be modified after its creation is the immutable object.
      • ■ Examples of immutable objects are list, array, set, and so on.
    • ○ Mutable object:
      • ■ An object that can be modified after its creation is the mutable object.
      • ■ Examples of mutable objects are integer, float, string, and so on.
  • • List is a mutable object since the elements in the list can be modified.
  • • Since list is mutable object, list cannot be a dictionary key.

Syntax:

In Python, the syntax to create the dictionary is as follows:

dictionary_name={key1:value1,key2:value2…}

In the above syntax,

  • • A dictionary can have multiple elements...

Blurred answer
Students have asked these similar questions
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}
Each item in a dictionary has two parts. What are they called?
Python coding language Create a static dictionary with a number of users and with the following values:  First name Last name Email address Password Ask the user for:          5. Email address        6. Password Loop (for()) through the dictionary and if (if()) the user is found print the following:          7. Hello, first name last name you have successfully logged in        8. Notify the user if the password and email address are wrong        9. Additional challenge: if you want the program to keep asking for a username and password when the combination is wrong, you will need a while() loop.      10. Save the file as assignment03yourlastname.py

Chapter 9 Solutions

Starting Out with Python (4th Edition)

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
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Systems Architecture
    Computer Science
    ISBN:9781305080195
    Author:Stephen D. Burd
    Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning