62.2k views
3 votes
Define a function createPhonebook that accepts three arguments: A list of first names A list of last names A list of phone numbers All three arguments will have the same number of items. createPhonebook should return a dictionary where the keys are full names (first name then last name) and the values are phone numbers. For example: firstNames

User Cherice
by
5.8k points

1 Answer

2 votes

Answer:

def createPhonebook(firsts, lasts, numbers):

d = {}

for i in range(len(firsts)):

k = firsts[i] + " " + lasts[i]

d[k] = numbers[i]

return d

Step-by-step explanation:

Create a function named createPhonebook that takes three arguments, firsts, lasts, numbers

Initialize an empty dictionary, d

Create a for loop that iterates the length of the firsts times(Since all the arguments have same length, you may use any of them). Inside the loop, set the key as the item from firsts, a space, and item from lasts (If the name is "Ted" and last name is "Mosby", then the key will be "Ted Mosby"). Set the value of the key as the corresponding item in the numbers list.

When the loop is done, return the d

User Wottensprels
by
4.9k points