0

I am trying to write a list comprehension which will select all numbers in a sequential list of numbers (whose length will change) which are divisible by 4.

end_of_quarter_dates = [i if i % 63 == 0 for i in range(0, 252)]

I am getting the error message "invalid syntax" for the beginning of the for loop.

Any thoughts appreciated.

GPB
  • 2,395
  • 8
  • 26
  • 36
  • As a side note, your code would test if the number is divisible by `63` and not by `4` as you specified in your question description. – Selcuk Mar 25 '19 at 03:20

1 Answers1

0

If you don't have else in the list comprehension, if has to be at the end:

end_of_quarter_dates = [i for i in range(0, 252) if i % 63 == 0]

Then it will work fine.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114