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
Define a function getSeconds() that accepts one argument: a list of lists. getSeconds() should return the...
Define a function getSeconds() that accepts one argument: a list of lists. getSeconds() should return the second item in every sublist that has at least two items. If the sublist has fewer than two items, it should be ignored. For example: getSeconds([[1,2], ['a', 'b', 'c'], ['x'], [10, 20]]) should be [2, 'b', 20]
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...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may be given a list of raw email addresses and be asked to generate meaningful information from such a list. This project involves parsing such a list and generating names and summary information from that list. The script, eparser.py, should: Open the file specified as the first argument to the script (see below) Read the file one line at a time (i.e., for line in...
Python A text file (WorldSeriesWinners.txt ) contains a chronological list of the World Series winning teams...
Python A text file (WorldSeriesWinners.txt ) contains a chronological list of the World Series winning teams from 1903 through 2009. The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2009. Note the World Series was not played in 1904 and 1994. Write a program to open the file WorldSeriesWinners.txt, read it line by line and store the team names in...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of userids on the command line 2. For each userid, display the userid, PID, CPU time, and current command for each process owned by that userid Your output should look similar to this example: practice-script-a doug.jones User: doug.jones PID: 8748 TIME: 00:00:00 COMMAND: /usr/lib/systemd/systemd --user User: doug.jones PID: 8749 TIME: 00:00:00 COMMAND: (sd-pam)    User: doug.jones PID: 8750 TIME: 00:00:00 COMMAND: sshd: doug.jones@pts/5 User: doug.jones...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT