How to Flatten a List of Lists in Python

Sometimes, when you’re working with data, you may have the data as a list of nested lists. A common operation is to flatten this data into a one-dimensional list in Python. Flattening a list involves converting a multidimensional list, such as a matrix, into a one-dimensional list.

To better illustrate what it means to flatten a list, say that you have the following matrix of numeric values:

>>>

>>> matrix = [
... [9, 3, 8, 3],
... [4, 5, 2, 8],
...

 

 

 

To finish reading, please visit source site