I’m trying to flatten a 2D list in python. The major issue is it looks something like this:
[a, b, c, [d, e, f, g, h], i, [j, k], etc]
since this is a mixture of a 1D and 2D list, how can I flatten it to:
[a, b, c, d, e, f, g, h, i, j, k, etc]
my current attempt looks something like this:
def flatten(array):
test = []
for i in range(len(array)):
try:
if array[i][0]:
for r in range(array[i]):
test.append(array[i][r])
except:
test.append(array[i])
return(test)