if you want to sum over even numbers, just do:
sum([j*2 for j in range(0, end_range/2)])
and yes, brackets supercede pythons "whitespace is syntax". if you need linebreaks where, ordinarily, linebreaks are not allowed, just write brackets.
if you want to sum over even numbers, just do:
sum([j*2 for j in range(0, end_range/2)])
and yes, brackets supercede pythons "whitespace is syntax". if you need linebreaks where, ordinarily, linebreaks are not allowed, just write brackets.
Given an iterable of pairs, sum the first elements of the pairs for which the first element of the pair is odd and the second element is truthy.
What the code you're suggesting does is, to be polite, unrelated.
i agree that i misinterpreted the codes intention.
Programming is more than that.
This is best: sum(range(0, end_range, 2))
;)
can they be great artisans? sure.
why do i think its not better? i said im not sure. i think the two options are about equal in readability, up to taste. yours is probably more efficient in terms of cpu cycles.
whats your sticking point?
It's not right. It doesn't give you the value 10, as you'd "expect".
2
2+4 = 6
2+4+6 = 12
if you sum even numbers, starting from 0, "10" is not a possible result. i dont know what youre trying to do there.
So it skips 10...
if you do sum(range(0,10,2)), 10 isn't reached either.
why are we having this discussion?
[j2 for j in range(0, (11+1)/2)]
Your code is wrong.
sum(range(0,11,2)) works as expected, [j*2 for j in range(0, (11)/2)] does not.
You seem like you have issues.