Suppose I have list_of_numbers = [[1, 2], [3], []]
and I want the much simpler object list object x = [1, 2, 3]
.
Following the logic of this related solution, I do
list_of_numbers = [[1, 2], [3], []]
import itertools
chain = itertools.chain(*list_of_numbers)
Unfortunately, chain
is not exactly what I want because (for instance) running chain
at the console returns <itertools.chain object at 0x7fb535e17790>
.
What is the function f
such that if I do x = f(chain)
and then type x
at the console I get [1, 2, 3]
?
Update: Actually the result I ultimately need is array([1, 2, 3])
. I'm adding a line in a comment on the selected answer to address this.