You pass the expression.
A list comprehension is given by square brackets ( [...] ). Understanding the list first creates the list object, so it uses syntax closely related to the syntax of the letter list:
list_literal = [1, 2, 3] list_comprehension = [i for i in range(4) if i > 0]
The generated expression, on the other hand, creates an iterator object. Only when iteration over this object is performed in a closed loop and elements are created. The generator expression does not store these elements; no list object is created.
The generator expression always uses (...) round parethesis, but when used as the only argument to call, the bracket may be omitted; the following two expressions are equivalent:
sum((i*i for i in xrange(5)))
Quote from the documentation of the generator expression:
Brackets can be omitted in calls with only one argument. See the Calls section for more details.
source share