Build Python lists from another iterable, and show the list comprehension and generator expression forms.
There are several ways to turn an iterable into a list, and they are not all the same. Some give you a list straight away, and one of them gives you something that only builds the items when you ask for them.
source = 'abc'
print(list(source)) # ['a', 'b', 'c']
print([c for c in source]) # ['a', 'b', 'c'] - the comprehension
print(list(range(3))) # [0, 1, 2]
print(sorted({3, 1, 2})) # [1, 2, 3] - sorted always returns a list
# A generator expression gives an iterator, not a list
lazy = (c for c in source)
print(type(lazy).__name__) # generator
print(list(lazy)) # ['a', 'b', 'c']
# Repetition builds a list of references
zeros = [0] * 5
print(zeros) # [0, 0, 0, 0, 0]
The call list(source) is the general conversion, and it works with any iterable, including generators and file objects. A list comprehension does the same job while letting you change or filter each item on the way. It is also usually faster, because the loop runs without the repeated method lookups that a normal Python loop performs.
The generator expression in parentheses looks almost the same as a comprehension in square brackets, but the difference is what you get back. The comprehension works out its result immediately and gives you a list. The generator expression gives you a generator object that works out each item only when it is needed, so nothing is stored and nothing is calculated until you actually loop over it.
The repetition form needs a warning. The list [0] * 5 is fine, because integers cannot change and each slot simply points at the same zero. But [[]] * 3 creates three references to the same inner list, so adding an item to one of them changes all three of them. To build three separate lists you need a comprehension, such as [[] for _ in range(3)].