This is not converting a 2d list to a 1d list. This is converting a list element (which happens to be a list) to multiple elements within the containing list. The input is not a list of lists.
I have a list like the following:
x = [1, [2,3,4], 5,....]
I want to convert it to this:
x = [1, 2, 3, 4, 5]
I know something like the following will work:
y = []
for _ in x:
if isinstance(_, list):
for i in _:
y.append(i)
else:
y.append(_)
But was hoping there was some more pythonic way like the following (obviously won't work):
x = [2, _ for _ in [2,3,4], 5]