16. Comprehending Comprehensions


#1



https://www.codecademy.com/en/courses/python-beginner-en-KAgt5/4/2?curriculum_id=4f89dab3d788890003000096


File "python", line 1
threes_and_fives = [for x in range(1,16): if x % 3 == 0 or x % 5 == 0]
^
SyntaxError: invalid syntax
Oops, try again. Did you create a list called threes_and_fives?


I don't know what's wrong.


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


#2

x for x in range(1, 16), you miss x before for. This is what will be appended to the list


#3

Sorry, what do you mean? I have not put an x in front of for.


#4

you haven't, and i am telling you should have + explain why


#5

Oh, sorry. I have tried and it still doesn't work.

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

#6

this is list comprehension, no need for a colon after if


#7

Sorry, never mind it works now! Thanks :relaxed:

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

#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.