Question
Consider the following scenario about using Python dictionaries and lists: Tessa and Rick are hosting a party. Before they send out invitations, they want to
Consider the following scenario about using Python dictionaries and lists:
Tessa and Rick are hosting a party. Before they send out invitations, they want to add all of the people they are inviting to a dictionary so they can also add how many guests each friend is bringing to the party.
Complete the function so that it accepts a list of people, then iterates over the list and adds all of the names (elements) to the dictionary as keys with a starting value of 0. Tessa and Rick plan to update these values with the number of guests their friends will bring with them to the party. Then, print the new dictionary.
This function should:
1.accept a list variable named guest_list through the functions parameter;
2.add the contents of the list as keys to a new, blank dictionary;
3.assign each new key with the value 0;
4. print the new dictionary.
def setup_guests(guest_list):
# loop over the guest list and add each guest to the dictionary with
# an initial value of 0
result = guests # Initialize a new dictionary
for x # Iterate over the elements in the list
___ # Add each list element to the dictionary as a key with
# the starting value of 0
return result
guests = ["Adam","Camila","David","Jamal","Charley","Titus","Raj","Noemi","Sakira","Chidi"]
print(setup_guests(guests))
# Should print {'Adam': 0, 'Camila': 0, 'David': 0, 'Jamal': 0, 'Charley': 0, 'Titus': 0, 'Raj': 0, 'Noemi': 0, 'Sakira': 0, 'Chidi': 0}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started