Question: Write a function that, given a 2D list, creates and returns a dictionary that has one key/value pair for each sublist. The key is

Write a function that, given a 2D list, creates and returns a dictionary that has one key/value pair for each Problem 2 (2D List to Dictionary V2) Might come in handy...  Iterating by position. Normally to iterate by You can assume all rows, including the header row at position 0, are the same length. Function name: name Grizz Carol attribute happy hugs  fault We want it to turn into a list of two dictionaries, each with Here are the specs:  Function name: find_max  Parameters: a dictionary where every value is a list, and an

Write a function that, given a 2D list, creates and returns a dictionary that has one key/value pair for each sublist. The key is the first element from the sublist (as a single element), and the value is the rest of the sublist (as a list). You can assume that the first element in each row is distinct, so you don't need to worry about overwriting keys. Here are the specs: Function name: Ist_to_det Parameters: a 2D list of any data type, of the form [[x, y, z], [x, y, z]...] Returns: a dictionary where the key = x and value = [y, z] for every row in the 2D list Examples of calling your function: 1st_to_dct ( [[1, 2, 3], [4, 5, 6]]) 1st_to_dct ( [[10, 11], [12, 13]]) Problem 2 (2D List to Dictionary V2) Might come in handy... returns (1 returns (10 [2, 3], 4 [5, 6]} [11], 12 [13]} Iterating by position. Normally to iterate by position over a 2d list, we would do.. for i in range (len (1st)): for j in range (len (1st[i])): # 1st[i][j] is the element at row i, column j Problem 2 (2D List to Dictionary V2) Might come in handy... Iterating by position. Normally to iterate by position over a 2d list, we would do.. for i in range (len (1st)): In this problem, we're swapping rows and columns so you probably won't want to use that exact setup, but the idea might be useful. for j in range (len (1st[i])): Write a function that, given a 2D list which includes a header, creates and returns a dictionary keyed on the header. name # 1st[i][j] is the element at row i, column j Imagine a 2d list representing a CSV file with a header, like this: attribute Grizz Carol happy hugs fault "attribute" : ["happy", "hugs"], "fault" ["barking", "jumping"]} barking jealous We want it to turn into a single dictionary where the keys come from the header, and the values are lists. {"name": ["Grizz", "Carol"], You can assume all rows, including the header row at position 0, are the same length. You can assume all rows, including the header row at position 0, are the same length. Function name: Ist_to_dct_v2 Parameters: a 2D list of any data type, including a header row at the beginning Returns: a dictionary keyed on the header row; each value is a list containing the elements of the column under the header Examples of calling your function: 1st_to_dct_v2([["h1", "h2"], [1, 2]]) returns {"h1" : [1], "h2" : [2]} 1st_to_dct_v2([["h1", "h2"], [1, 2], [3, 4]]) returns {"h1" : [1, 3], "h2" [2, 4]} Problem 3 (2D List to List of Dictionaries) Might come in handy... In this case the header will be at 1st [0], and the main data will be at 1st [1:] Because we're making a list of dictionaries, you should make a new list (newlst least once, and a new dictionary (dct = {}) many times. = []) at Write a function that, given a 2D list which includes a header, creates and returns a list dictionaries. All the dictionaries have the same keys, which come from the header. Imagine a 2d list representing a CSV file with a header, like this: name Grizz Carol attribute happy hugs fault We want it to turn into a list of two dictionaries, each with three key/value pairs, like this: [{"name": "Grizz", "attribute" : "happy", "fault": "barking"}, {"name": "Carol", "attribute" : "hugs", "fault": "jealous"} ] barking jealous You can assume the given list is not empty, and that every sublist is the same length. Here are the specs: Function name: Ist_to_dct_lst Parameters: a 2D list of any data type, of the form [[h1, h2, h3], [x, y, z], [x, y, z]...] Returns: a list of dictionaries where the keys all come from the header row and values from each sublist Problem 4 (Max in a Dictionary of Lists) Examples of calling your function: 1st_to_dct_1st([[h1, h2], [1, 2], [4, 5]])..... returns[ {h1 : 1, h2: 2}, {h1 : 4, h2, 5} ] Might come in handy... Python has a built-in max function that can accept a list. However if you give max a dictionary, it will find the maximum key, not maximum value. You can use list (dct.keys()) or list (dct.values()) to turn the keys or values of a dictionary into an actual list data type Pythons 1st.index(value) method returns the position of the first occurrence of value in the list lst. Write a function that takes in a dictionary like you would have produced in Problem 1. This dictionary has all of its values as lists, and we want to find the largest element at a given position among all of them. For example, if the given position is 1, then look at all the position 1s in all of the lists, and return the key where the element at position 1 is the largest. Here are the specs: Function name: find_max Parameters: a dictionary where every value is a list, and an integer for a position Returns: the key in the given dictionary, where its value at a given position is the highest Examples of calling your function: find_max({"a" : [1, 5], "b" : [4, 3]}, 0) find_max({"a" : [1, 5], "b" : [4, 3]}, 1) Problem 5 (List of Sums) Might come in handy... List comprehension. This is a quick way to make a new list with 10x the value from an original 1st.... newlst = [num * 10 for num in 1st] Remember that it's totally fine to write small helper functions, or to call functions you've already written. Write a function that takes in a 2d list. You can assume every element in the list is a number. Your function should create and return a list of numbers that represents the sum of each column. Here are the specs: returns "b" returns "a" Function name: sum_cols Parameters: a 2d list of numbers Returns: a list of numbers, the sum of each column

Step by Step Solution

3.33 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Certainly Ill provide Python code for each of the problems you described Problem 1 2D List to Dictio... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!