This function is commonly referred to as flatten.
You can use a library like numpy https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flatten.html
>>> a = np.array([[1,2], [3,4]])
>>> a.flatten()
array([1, 2, 3, 4])
>>> a.flatten('F')
array([1, 3, 2, 4])
It's simple to implement with lambda.
flatten = lambda l: [item for sublist in l for item in sublist]
© 2024 OneMinuteCode. All rights reserved.