I have a list of lists of lists with strings, something like this (representing chapters, paragraphs and sentences of a text)):
[ [[ ['chp1p1s1'], ['chp1p1s2'], ['chp1p1s3'] ],
[ ['chp1p2s1'], ['chp1p2s2'], ['chp1p2s3'] ]],
[[ ['chp2p1s1'], ['chp2p1s2'], ['chp2p1s3'] ],
[ ['chp2p2s1'], ['chp2p2s2'], ['chp2p2s3'] ]] ]
I know how to flatten this list completly (for example by [x for y in z for x in y]), but what I would like to do is to flatten it partially, to finally look like this:
[ [ ['chp1p1s1'], ['chp1p1s2'], ['chp1p1s3'],
['chp1p2s1'], ['chp1p2s2'], ['chp1p2s3'] ],
[ ['chp2p1s1'], ['chp2p1s2'], ['chp2p1s3'],
['chp2p2s1'], ['chp2p2s2'], ['chp2p2s3'] ] ]
I managed to solve this by some for loops:
semiflattend_list=list()
for chapter in chapters:
senlist=list()
for paragraph in chapter:
for sentences in paragraph:
senlist.append(sentences)
semiflattend_list.append(senlist)
But I wonder if there is a better, shorter solution? (I don't think, zip is a way to go, because my lists are different in size.)