list. entry will be the list created for the second dictionary, and so on.) eated for the first dictionary; the second entry Each entry in the returned list will contain a list of values from that dictionary. The second parameter's entries specify the keys whose values should be added to this list. The order of these values must parallel the order of the keys in the second parameter. (So first will be the value associated with the second parameter's first entry, second will be the value associated with the second parameter's second entry, and so on.) You SHOULD assume that every dictionary will contain all of the keys from the first parameter. Python creates a new list only when a variable is assigned a list literal. You MUST include the statement initializing the variable to which the dictionary's values are added INSIDE the for-loop iterating through the first parameter. As an example, if this were a function call: list_gen ([{'Used Key': 'Data', 'Unused Keys': 'More Data'}], ['Used Key']) the expected return value would be: [ ['Data']] As an second example, if this were a function call: list_gen ([{'Hint': 'Length 2 Not Required', 'Num': 8675309), {'Num': 1, 'Hint': 'Use 1st param order'}], ['Hint', 'Num']) the expected return value would be: [['Length 2 Not Required', 8675309], ['Use 1st param order', 1] I Page 3/ +
list. entry will be the list created for the second dictionary, and so on.) eated for the first dictionary; the second entry Each entry in the returned list will contain a list of values from that dictionary. The second parameter's entries specify the keys whose values should be added to this list. The order of these values must parallel the order of the keys in the second parameter. (So first will be the value associated with the second parameter's first entry, second will be the value associated with the second parameter's second entry, and so on.) You SHOULD assume that every dictionary will contain all of the keys from the first parameter. Python creates a new list only when a variable is assigned a list literal. You MUST include the statement initializing the variable to which the dictionary's values are added INSIDE the for-loop iterating through the first parameter. As an example, if this were a function call: list_gen ([{'Used Key': 'Data', 'Unused Keys': 'More Data'}], ['Used Key']) the expected return value would be: [ ['Data']] As an second example, if this were a function call: list_gen ([{'Hint': 'Length 2 Not Required', 'Num': 8675309), {'Num': 1, 'Hint': 'Use 1st param order'}], ['Hint', 'Num']) the expected return value would be: [['Length 2 Not Required', 8675309], ['Use 1st param order', 1] I Page 3/ +
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
Related questions
Question
100%
so im having an issue writing this code. the question, plus the errors are shared in screenshots. please, please, if an expert can help me correct this, id immensely appreciate it
def list_gen(d, l):
result = []
for k in d:
x = []
sorted_dict = dict()
sorted_list = list((i, k[i]) for i in l)
for i in sorted_list:
sorted_dict.setdefault(i[0], i[1])
for key, value in sorted_dict.items():
if key in l:
x.append(value)
result.append(x)
return result
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr