All print output should include descriptions as shown in the example output below. 1) Dictionary Basics: a. Create a dictionary of fruit and desserts made from the fruit. The fruit should be the key and the dessert should be the value. Use these key value pairs: apple: sauce peach: cobbler carrot cake strawberry:sorbet banana:cream pie b. Add the mango fruit to the dictionary. Its dessert is sticky rice. c. Change the strawberry dessert to shortcake. d. Carrot is not a fruit, so remove carrot from the dictionary. e. Print the apple dessert. f. See if a banana dessert exists. g. See if a pear dessert exists. h. Print the keys in the dessert dictionary. i. Print the values in the dessert dictionary. j. Print the key-value pairs in the dessert dictionary. 2) Combining dictionaries: a. Create a dictionary named capitols1 and populate it with these key value pairs: Alabama: Montgomery Alaska:Juneau Arizona: Phoenix Arkansas: Little Rock California:Sacramento b. Create a dictionary named capitols2 and populate it with these key value pairs: California:Sac. Colorado: Denver Connecticut: Hartford Be sure that the California capitol is Sac. and not Sacramento. c. Using the dictionary update() method, update capitols1 with capitols2. d. Print the sorted capitols (values). Note the updated value of California's capitol. 3) Sets Basics: a. Create a set named class1 and populate it with the students Li, Audry, Jia, Migel, Tanya. b. Create a set named class2 and populate it with the students Sasha, Migel, Tanya, Hiroto, Audry. c. Add John to class 1. d. Print a sorted list of students who are in both classes. e. Print a sorted list of all students. f. Test to see if Sasha is in class 1.
pyth code please
//Python Code:
# Create a dictionary of fruit and desserts made from the fruit. fruit is the key and the dessert is the value.
fruit_desserts = {'apple': 'sauce', 'peach': 'cobbler', 'carrot': 'cake', 'strawberry': 'sorbet', 'banana': 'cream pie'}
# Add the mango fruit to the dictionary. Its dessert is sticky rice.
fruit_desserts['mango'] = 'sticky rice'
# Change the strawberry dessert to shortcake.
fruit_desserts['strawberry'] = 'shortcake'
# remove carrot from the dictionary.
fruit_desserts.pop("carrot")
# Print the apple dessert.
print(f"apple dessert is: {fruit_desserts['apple']}")
# See if a banana dessert exists.
print(f"banana dessert exists: {'banana' in fruit_desserts}")
# See if a pear dessert exists.
print(f"pear dessert exists: {'pear' in fruit_desserts}")
# Print the keys in the dessert dictionary.
print(f"{fruit_desserts.keys()}")
# Print the values in the dessert dictionary.
print(f"{fruit_desserts.values()}")
# Print the key-value pairs in the dessert dictionary.
print(f"{fruit_desserts.items()}")
Step by step
Solved in 6 steps with 3 images