How to Flatten a List of Lists in Python

0%

Fill in the blanks:

Given a matrix represented as a list of lists in Python, you can flatten it into a one-dimensional list using a simple method. For example, if you have the following matrix:

Python
matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]

You can flatten this matrix into a single list using a :

Python
[item for row in matrix for  in ]

Running this code will create a flattened list [1, 2, 3, 4, 5, 6, 7, 8, 9].

Sorry! There has been an error processing your answer. Please try again.

Got feedback on this question?