Here is an example of how to build a dictionary.
phonebook = {} phonebook["Paul"] = 4071234545 phonebook["Joe"] = 4074451234 phonebook["Patsy"] = 4076645651 print(phonebook) print(phonebook["Paul"]) print(phonebook["Joe"]) print(phonebook["Patsy"]) print("\n" + str(type(phonebook)) + "\n") print(phonebook)
Just press Run!
I sneakly snuck str(type(phonebook)) into this example - as an example to cast one type of object to a string to get it to print cleanly.


This is another notation for intializing the dictionary.
phonebook = { "Paul" : 4071234545, "Joe" : 4074451234, "Patsy" : 4076645651 } print(phonebook)
Just press Run!



To remove a specified index, use either one of the following notations:
phonebook = { "Paul" : 4071234545, "Joe" : 4074451234, "Patsy" : 4076645651 } print(phonebook) del phonebook["Joe"] print(phonebook) phonebook.pop("Paul") print(phonebook)
Just press Run!

Exercise:

In this exercise, you will need to add and remove entries from the dictionary below.
phonebook = { "Paul" : 4071234545, "Joe" : 4074451234, "Patsy" : 4076645651, "James" : 2153343434, "Steve" : 2078823456, "Heather" : 222234234 } # write your code # testing code if "Melody" in phonebook: print("Melody is listed in the phonebook.") if "James" not in phonebook: print("James is not listed in the phonebook.") phonebook = { "Paul" : 4071234545, "Joe" : 4074451234, "Patsy" : 4076645651, "James" : 2153343434, "Steve" : 2078823456, "Heather" : 222234234 } # write your code here phonebook["Melody"] = 4078823411 del phonebook["James"] # testing code if "Melody" in phonebook: print("Melody is listed in the phonebook.") if "James" not in phonebook: print("James is not listed in the phonebook.") test_output_contains("Melody is listed in the phonebook.",no_output_msg= "You did not add Melody after the comment correctly!.") test_output_contains("James is not listed in the phonebook.",no_output_msg= "You did not delete James using the del command!.") success_msg("Nice work!")
Look at the top examples to access and add and remove to dicts!