Define a function createPhonebook that accepts three arguments:
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 = ['Jay', 'Daisy', 'Nick', 'Myrtle'] lastNames = ['Gatsby', 'Buchanan', 'Carraway', 'Wilson'] phones = ['5551212', '4441234', '4568309', '1456871'] phonebook = createPhonebook(firstNames, lastNames, phones) # phonebook should be: { # 'Jay Gatsby': '5551212', # 'Daisy Buchanan': '4441234', # 'Nick Carraway': '4568309', # 'Myrtle Wilson': '1456871' # }
def createPhonebook(firstNames, lastNames, phones): d = {} for i in range(len(firstNames)): d[firstNames[i] + ' ' + lastNames[i]] = phones[i] return d # Testing the function here. ignore/remove the code below if not required if __name__ == '__main__': firstNames = ['Jay', 'Daisy', 'Nick', 'Myrtle'] lastNames = ['Gatsby', 'Buchanan', 'Carraway', 'Wilson'] phones = ['5551212', '4441234', '4568309', '1456871'] phonebook = createPhonebook(firstNames, lastNames, phones) print(phonebook)
Get Answers For Free
Most questions answered within 1 hours.