Append to an empty list using a single line for-loop python

appendlistpython-3.x

I am trying to append numbers from a generator to an empty list using a single line for loop but it returns None. I understand it can be done using a for loop with 2 lines but I was wondering what I am missing. i.e.,

>>> [].append(i) for i in range(10)

[None, None, None, None, None, None, None, None, None, None]

I was hoping to create this in one line:

>>> [].append(i) for i in range(10)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Thank you.

Best Solution

Write a proper comprehension, without append.

>>> [i for i in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(i for i in range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]