I have a small problem where I lack quite some Python experience. Assuming a list:
list=[[40, 20, 45, 40], [[20, 10, 10, 30, 45, 20], [30, 20, 20, 30]]]
I want to do something I call 'partial flattening' because the expected output is:
[[40, 20, 45, 40], [20, 10, 10, 30, 45, 20], [30, 20, 20, 30]]
Notice before the lentgh of list
was 2
while the expected output has length of 3
. The problem is that I don't know in advance which element from list
is nested one layer deeper.
This answer and many others didn't help much, because the flattening goes to far. Following the question the output is:
list=[40, 20, 45, 40, [20, 10, 10, 30, 45, 20], [30, 20, 20, 30]]
(notice the missing brackets for the first 4 elements from the list.