a = [
[1, 2],
[1, 2]
]
print([x for x in [x for x in a]])
[[1, 2], [1, 2]]
But I want to see something like that:
[1, 2, 1, 2]
How I cad do this?
a = [
[1, 2],
[1, 2]
]
print([x for x in [x for x in a]])
[[1, 2], [1, 2]]
But I want to see something like that:
[1, 2, 1, 2]
How I cad do this?
Try this.
a = [
[1, 2],
[1, 2]
]
lst = [q for i in a for q in i]
print(lst)
The above one is not always working it gives you an error if the list is something like this.
a = [[1, 2],[1, 2],2]
But this one always work.
a = [
[1, 2],
[1, 2]
]
lst = []
for i in a:
if type(i) == list:
lst.extend(i)
else:
lst.append(i)
print(lst)
a = [
[1, 2],
[1, 2]
]
flatten_list = lambda y:[x for a in y for x in flatten_list(a)] if type(y) is list else [y]
print(flatten_list(a))