I am learning Python and I am trying out some exercises. I am trying to sum all the odd numbers from 0 to 9 using list comprehension, for and if in one line.
I tried the following code:
for idx in range(10): s = 0 if idx == 0 else s = [(i % 2) for i in range(10)][idx] * range(10)[idx] + s but I get the following error:
SyntaxError: can't assign to conditional expression I don't quite understand it.
Your advice will be appreciated.