I currently have a list like this:
[3, 4, ['x', 'y', 'z'], 5]
and want to make it to
[3, 4, 'x', 'y', 'z', 5]
New beginner at this, and tried searching around, but couldn't find anything I could understand.
I currently have a list like this:
[3, 4, ['x', 'y', 'z'], 5]
and want to make it to
[3, 4, 'x', 'y', 'z', 5]
New beginner at this, and tried searching around, but couldn't find anything I could understand.
l=[3, 4, ['x', 'y', 'z'], 5]
nl=[]
for x in l:
if not isinstance(x,int):
for y in x:
nl.append(y)
else:
nl.append(x)
print(nl)
One liner
l=[3, 4, ['x', 'y', 'z'], 5]
nl=[];[nl.extend([x] if isinstance(x,int) else x) for x in l]
It is not flatening list of list because the given one is combination of list and int