I am trying to add numbers from a generator to an empty list using one line for a loop, but returns None . I understand that this can be done using a for loop with two lines, but I was wondering what I did not see. those.
>>> [].append(i) for i in range(10)
[None, None, None, None, None, None, None, None, None, None]
I was hoping to create this on one line:
>>> [].append(i) for i in range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Thanks.
source share