3 ms·
The first is a transform of the values (with only that, the list stays the same length, the IF says whether the transform happens or doesn't for each value), th
by jodrellblank 5y ago
The first is a transform of the values (with only that, the list stays the same length, the IF says whether the transform happens or doesn't for each value), the second is a WHERE filter picking or dropping some values (list might shrink), you can have both (list shrinks and the selected values are transformed):
>>> list([ x if x > 1 else x*2 for x in a if x <3] )
[2, 4]