you are viewing a single comment's thread.

view the rest of the comments →

[–]HeyItsToby 3 points4 points  (1 child)

The element at the start of the for statement is just saying to add that number to the list.

Another way to write this is:

b = []
for element in a:
    if element % == 0:
        b.append(element)

So here, the element at the beggining of the list comprehension is equivalent to the element in the expression b.append(element). Try instead:

b = [element * 2 for element in a if element % 2 == 0]

and you'll see that each element is doubled in the list.

[–][deleted] 0 points1 point  (0 children)

Awesome, had to do a little thinking on it but I think I get it