Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

Students also viewed these Databases questions

Question

6. Explain the power of labels.

Answered: 1 week ago

Question

10. Discuss the complexities of language policies.

Answered: 1 week ago