Knowee
Questions
Features
Study Tools

Dictionary Creation: a. Create a dictionary named contacts with keys 'Alice' and 'Bob' mapped to their respective email addresses.Dictionary Operations: a. Retrieve the email address of 'Alice' from the dictionary contacts. b. Add a new key-value pair to contacts with 'Eric' mapped to '[email protected]'. c. Delete the entry for 'Alice' from the dictionary contacts.

Question

Dictionary Creation: a. Create a dictionary named contacts with keys 'Alice' and 'Bob' mapped to their respective email addresses.Dictionary Operations: a. Retrieve the email address of 'Alice' from the dictionary contacts. b. Add a new key-value pair to contacts with 'Eric' mapped to '[email protected]'. c. Delete the entry for 'Alice' from the dictionary contacts.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Step 1: Dictionary Creation To create a dictionary named "contacts" with keys 'Alice' and 'Bob' mapped to their respective email addresses, you can use the following code:

contacts = {'Alice': '[email protected]', 'Bob': '[email protected]'}

Step 2: Dictionary Operations a. To retrieve the email address of 'Alice' from the dictionary contacts, you can use the following code:

alice_email = contacts['Alice']
print(alice_email)

b. To add a new key-value pair to contacts with 'Eric' mapped to '[email protected]', you can use the following code:

contacts['Eric'] = '[email protected]'

c. To delete the entry for 'Alice' from the dictionary contacts, you can use the following code:

del contacts['Alice']

After executing these steps, the dictionary contacts will have the updated values.

This problem has been solved

Similar Questions

) Write a program to input your friends' names and their Phone Numbers and storethem in the dictionary as the key-value pair. Perform the following operations on thedictionary: (3)i) Display the name and phone number of all your friendsii) Add a new key-value pair in this dictionary and display the modifieddictionaryiii) Delete a particular friend from the dictionaryiv) Modify the phone number of an existing friendv) Check if a friend is present in the dictionary or notvi) Display the dictionary in sorted order of name

Write a class that represents a person’s mailing address. It should have separate fields forthe name, street address, city, state and ZIP code. Write an application AddressBook, toincorporate address book application :-(a) To add addresses.(b) Print addresses.

Write a Python program to create a new dictionary by extracting the mentioned keys and create a new new dictionary and print it as the result.

A fundamental concept of dictionary is that all its keys are unique. This is used ina lot of daily scenarios. For example, your student number uniquely identifiesyou at HKU and every office at HKU can use this number to link the data aboutyou. This concept can be used to implement a database where a unique key isused to identify all the data associated with this key.We will simulate a simple university database using dictionaries. Thedictionaries in the database are linked by unique keys that can be used toidentify a specific entry in a dictionary. For example, one of the dictionaries inthe database is a timetable dictionary that contains the timetable of differentcourses where each entry contains course_ID, teacher_ID, start_time, end_timeand venue_ID. The timetable dictionary can be linked to another dictionarycalled teacher dictionary by teacher_ID. We can therefore use the teacher_IDstored in the timetable dictionary as a key to retrieve the information of thecorresponding teacher stored in the teacher dictionary

Write a program that prints all the keys and values in a dictionary where the key is "dennis" and the value is "student."

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.