Question

Define a function createPhonebook that accepts three arguments: A list of first names A list of...

Define a function createPhonebook that accepts three arguments:

  1. A list of first names
  2. A list of last names
  3. 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 =   ['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'
# }

Homework Answers

Answer #1
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)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a program that allows the user to input a list of first names into one...
Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of emial addresses where the address is of the following form: [email protected] Declare FirstName[100] as String Declare LastName[100] as String Declare email as String Declare K as Integer Declare index as Integer Write "Enter first and last name." Write...
Define a function math(num1, num2, operation) that takes three arguments and it should perform math operations...
Define a function math(num1, num2, operation) that takes three arguments and it should perform math operations ( +,-,* and /) on two numbers num1 and num2 based on the operation symbol, and then it should return the result. The main part of the program should prompt users to provide num1, num2, and an operation symbol separately and then call the function with user inputs and display the result back to the user. Function definition should look like this in your...
Define a function in Scheme which takes a list of numbers and a scalar and returns...
Define a function in Scheme which takes a list of numbers and a scalar and returns the rest of the list after the first occurrence of the scalar that was passed. An empty list should be returned if the value doesn't exist. For example, (list-past-scalar '(5 2 8 3 1 9 2 3) 3) #returns (1 9 2 3) (list-past-scalar '(37 18 38 65 90) 100) #returns ()
Define and test a function myRange. This function should behave like Python’s standard range function, with...
Define and test a function myRange. This function should behave like Python’s standard range function, with the required and optional arguments, but it should return a list. Do not use the range function in your implementation! Study Python’s help on range to determine the names, positions, and what to do with your function’s parameters. Use a default value of None for the two optional parameters. If these parameters both equal None, then the only provided argument should be considered the...
**please write code with function definition taking in input and use given variable names** for e.g....
**please write code with function definition taking in input and use given variable names** for e.g. List matchNames(List inputNames, List secRecords) Java or Python Please Note:    * The function is expected to return a STRING_ARRAY.      * The function accepts following parameters:      *  1. STRING_ARRAY inputNames      *  2. STRING_ARRAY secRecords      */ Problem Statement Introduction Imagine you are helping the Security Exchange Commission (SEC) respond to anonymous tips. One of the biggest problems the team faces is handling the transcription of the companies reported...
Create a hash table in C++ for names (first name and last name only, no telephone...
Create a hash table in C++ for names (first name and last name only, no telephone numbers), and use the following to generate the keys: unsigned char key = 0; for (int i = 0; i < fullName.length(); i++)         key ^= fullName[i]; Your instructor will be using the following list of names to test your program: Uzoma Acholonu Giuliana Asmad Michael Atkins-Combs Vishnu Bakthisaran Christopher Blowars William Bronson Trevor Butcher Tiffany Caceres-Bonilla Dulce Castro David Cifuentes Daniel Coursen Alexandra...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of...
What would the pseudocode be for this? The code for this has already been answered. I...
What would the pseudocode be for this? The code for this has already been answered. I need the pseudocode. Credit card numbers typically consist of 13, 15, or 16 digits. For example, 4690 3582 1375 4657 is a hypothetical credit card number. The first digit designates the system. In (3.1.1), the first digit, 4, shows that the card would be a Visa card. The following digits specify other information such as the account number and bank number. (The precise meaning...
using mysql lyrics.database. i will provide the lyrics schema database info below 1. List the first...
using mysql lyrics.database. i will provide the lyrics schema database info below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in...
CASE 3.2 Horizon Consulting Patti Smith looked up at the bright blue Carolina sky before she...
CASE 3.2 Horizon Consulting Patti Smith looked up at the bright blue Carolina sky before she entered the offices of Horizon Consulting. Today was Friday, which meant she needed to prepare for the weekly status report meeting. Horizon Consulting is a custom software development company that offers fully integrated mobile application services for iPhonetm, Androidtm, Windows Mobile® and BlackBerry® platforms. Horizon was founded by James Thrasher, a former marketing executive, who quickly saw the potential for digital marketing via smartphones....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT