Question

(Python 3) If I have a list of keys and 3 lists of values, how can...

(Python 3) If I have a list of keys and 3 lists of values, how can I append these values into an existing key, value pair in a dictionary? Say I have:

mykeys = ["John", "Sarah", "Lexi, "Cass"]

values1 = [3, 5, 2, 6]

values2 = [17, 18, 12, 21]

values3 = [4, 7, 3, 0]

How can I make it so my dictionary contains all three values in each of the keys. i.e.:

{"John" : [3, 17, 4], "Sarah": [5, 18, 7], "Lexi": [2, 12, 3], "Cass": [6, 21, 0]}

I know how I can append each of the values by hand, but I'm wondering if there's some kind of function I can write to do this for me.

Homework Answers

Answer #1
def prepare_dictionary(keys, values1, values2, values3):
    d = {}
    for i in range(len(keys)):
        d[keys[i]] = [values1[i], values2[i], values3[i]]
    return d


mykeys = ["John", "Sarah", "Lexi", "Cass"]
values1 = [3, 5, 2, 6]
values2 = [17, 18, 12, 21]
values3 = [4, 7, 3, 0]
print(prepare_dictionary(mykeys, values1, values2, values3))

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
I need a breakdown to perform in excel for numbers 7,8,9. I am unsure of how...
I need a breakdown to perform in excel for numbers 7,8,9. I am unsure of how I calculate the times. heres the data set and the questions. Calculate the probability that a flight will depart early or on time. Calculate the probability that a flight will arrive late. Calculate the probability that a flight departs late or arrives early. DEP_Delay ARR_Delay -4 0 -3 -3 0 -5 -7 -1 8 3 -1 -5 3 8 11 6 -6 0 -5...
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
Create an MS word document that lists each Quantitative variable in the Class Survey Data, provide...
Create an MS word document that lists each Quantitative variable in the Class Survey Data, provide a point estimate of the mean (the sample mean) and a 95% Confidence Interval for the sample mean for each variable. Watch TV Credits Sleep Work (hrs) Songs downloaded FB Friends 1 15 7 50 50 34 0 14 8 30 2000 0 1 16 6 0 500 300 4 21 4.5 0 0 635 0 16 8 3 290 0 0 19 6.5...
Find the Mean, Median, and the Mode of the following values: i 1 2 3 4...
Find the Mean, Median, and the Mode of the following values: i 1 2 3 4 5 6 7 8 9 10 x 10 15 15 17 21 24   24   25 28 32
Dep Delay Arr Delay q1 -13 -9 q3 1 3 IQR 14 12 stdev 9.211846 9.660933...
Dep Delay Arr Delay q1 -13 -9 q3 1 3 IQR 14 12 stdev 9.211846 9.660933 negative 291 zero 39 positive 170 total (should be 500) 500 all data is for arrival data. please help me explain these can someone help me answer these questions and tell me how to put them in excel.thanx in advance 1.    Define a random variable (X) so that your chosen data set represents values of X. 2.    Is your chosen random variable discrete or...
   4.     a) i) If 4 individuals are selected from a group of 7 people,                    how...
   4.     a) i) If 4 individuals are selected from a group of 7 people,                    how many possible selection option could be made?                                 ii) In a competition prizes are given to 6 of the 10 participants.                  How many possible prize lists could be made if they are given different prizes?                                                                                                                                 b) In how many ways can the letters of the word SEMESTER be rearranged?                                                                                                             5) If the fifth term of a AP is...
How I can Make a scatterplot of horse age to price? 2) how I can Run...
How I can Make a scatterplot of horse age to price? 2) how I can Run a correlation of age to price? NAME SEX AGE HEIGHT HANDS WEIGHT Height INCHES PRICE JR 2 16 16,3 1174 67 $2.543 Bently 2 15 14,4 887 60 $6.748 Cujo 2 14 15,2 1002 62 $2.704 Blk Jk 2 10 14,2 903 58 $2.281 George 2 20 15,2 1064 62 $5.213 Baldy 2 14 13,1 759 53 $3.493 Annie 0 9 13,2 738 54...
The table lists the number of defective 60-watt lightbulbs found in samples of 100 bulbs selected...
The table lists the number of defective 60-watt lightbulbs found in samples of 100 bulbs selected over 25 days from a manufacturing process. Assume that during this time the manufacturing process was not producing an excessively large fraction of defectives. Day 1 2 3 4 5 6 7 8 9 10 Defectives 5 2 6 8 4 4 5 6 7 2 Day 11 12 13 14 15 16 17 18 19 20 Defectives 2 5 3 4 1 3...
The table lists the number of defective 60-watt lightbulbs found in samples of 100 bulbs selected...
The table lists the number of defective 60-watt lightbulbs found in samples of 100 bulbs selected over 25 days from a manufacturing process. Assume that during this time the manufacturing process was not producing an excessively large fraction of defectives. Day 1 2 3 4 5 6 7 8 9 10 Defectives 5 3 5 8 4 5 4 6 6 2 Day 11 12 13 14 15 16 17 18 19 20 Defectives 3 5 4 4 1 2...
I am trying to figure out how to find the most common word length in the...
I am trying to figure out how to find the most common word length in the british dictionary. I have inputted the text file for the british dictionary into my program. I tried a tedious way, but it doesn't seem effective. Can someone help me? String longestWord = "";        int maxLength =0;        int count1 =0, count2 =0, count3=0, count4=0, count5=0, count6=0, count7=0, count8=0, count9=0, count10=0;        Scanner scanFile = new Scanner (new File("BritishDictionary.txt"));       ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT