On 03.12.2015 10:27, [email protected] wrote:
>
> I often saw constructions like this
> x for x in y if ...
> But I don't understand that combination of the Python keywords (for,
> in, if) I allready know. It is to complex to imagine what there really
> happen.
>
> I understand this
> for x in y:
> if ...
>
> But what is about the 'x' in front of all that?
>
The leading x states which value you want to put in the new list. This
may seem obvious in the simple case, but quite often its not the
original x-ses found in y that you want to store, but some
transformation of it, e.g.:
[x**2 for x in y]
is equivalent to:
squares = []
for x in y:
squares.append(x**2)
--
https://mail.python.org/mailman/listinfo/python-list