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 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 function’s 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}  

5HXZ4C The Asker · Computer Science

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 function’s 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}

 

More
Community Answer
D4RITF

【General guidance】The answer provided below has been developed in a clear step by step manner.Step1/1Here's the complete implementation:def setup_guests(guest_list): # Initialize a new dictionary with the starting value of 0 for each key result = {x: 0 for x in guest_list} return resultguests = ["Adam","Camila","David","Jamal","Charley","Titus","Raj","Noemi","Sakira","Chidi"]print(setup_guests(guests))Explanation:Explanation: Define the function setup_guests(guest_list) that takes a list of guests as its argument.Initialize a new dictionary result using a dictionary comprehension. This will create a dictionary with keys for each element in the guest_list and a value of 0 for each key. The syntax for a dictionary comprehension is ... See the full answer