I have a list of lists of integers like this:
x = [[1], [2], [3]]
How do I convert it to a list of integers:
x = [1, 2, 3]
I was wondering if there are other ways to do it besides a for loop. Thanks!
I have a list of lists of integers like this:
x = [[1], [2], [3]]
How do I convert it to a list of integers:
x = [1, 2, 3]
I was wondering if there are other ways to do it besides a for loop. Thanks!
I would go for using .extend()
if you don't want to use a double for loop.
y = []
for small in x:
y.extend(small)
But if a double for loop is fine for you then this could work too
y = [num for sub in x for num in sub]
output
[1, 2, 3]