16. Comprehending Comprehensions


#1

Can someone advise why the code below doesn't work?

threes_and_fives = [x for x in range(1,16), if (x % 3 == 0) or (x % 5 == 0)]
print threes_and_fives

Produces the following error message:

File "python", line 1
threes_and_fives = [x for x in range(1,16), if (x % 3 == 0) or (x % 5 == 0)]
                                             ^

SyntaxError: invalid syntax


#2

nevermind, solved by removing the "," before if.

threes_and_fives = [n for n in range(1,16) if n % 3 == 0 or n % 5 == 0]
print threes_and_fives