Flattening lists of lists is a well-known problem but how does one flatten a list of lists of lists in the most pythonic way? My ultimate goal is to create a numpy array as follows:
[In]: mylist = [[[1,2,3], [4]], [[5,6], [7,8]]]
[Out]: array([[1, 2, 3, 4],
[5, 6, 7, 8]])
but even just completely flattening into a long list will do (can be easily converted into the right-shaped array anyway). A typical output array will have dimensions (10000, 10) so looping through the rows-to-be is very inefficient. All ideas will be appreciated!
(edit) Best solution I can think of:
import itertools
for i in range(len(mylist)):
mylist[i] = list(itertools.chain.from_iterable(mylist[i]))
np.array(mylist)