I'm still new to python. Some of the exercises I'm working on are things like 'return a list of integers up to but less than n' or 'return a list of odd (or even) integers up to but less than n', etc.
Seems reasonably straight-forward, and I was able to understand how to make a short function that does these things. For example, for generating a list of odd numbers...
def odds(n)
return [i for i in range(n) if (i % 2 == 1)]
... works just fine.
But the suggested solution was:
def odds(n)
return [i for i in range(n) if i % 2]
This returns the same thing. But I don't understand the 'if i % 2' at the end. How can this work when we haven't clarified what the 'i % 2' test needs to evaluate to???