Question: For Python 2.7 We discussed list comprehensions, which take the form of: new_list = [expression for name in list] where name can be used in
For Python 2.7

We discussed list comprehensions, which take the form of: new_list = [expression for name in list] where name can be used in expression. It is also possible for expression to be another list comprehension! Nesting two list comprehensions in this way results in the following form: new_list = [[expression for name2 in list2] for name 1 in list1] where both name1 and name2 can be used in expression. Write a nested list comprehension that transposes the following "matrix" A: A = [[10, 20, 30, 40, 50, 60], [11, 21, 31, 41, 51, 61], [12, 22, 32, 42, 52, 62], [13, 23, 33, 43, 53, 63], [14, 24, 34, 44, 54, 64], [15, 25, 35, 45, 55, 65], [16, 26, 36, 46, 56, 66]] Here is a hint to get you started. The form of your list comprehension should look like this: transpose [[??????????????????] for i, _ in enumerate (A [0])] Start by asking yourself, "What is i and how could it be useful?" Next, think about what the contents of each row of the resulting transposed matrix should be
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
