2 ms·
More idiomatic Python, and quite clear IMHO print sum(x if x % 3 == 0 or x % 5 == 0 else 0 for x in range(1, 1000))
by Sheepshow 13y ago
More idiomatic Python, and quite clear IMHO
print sum(x if x % 3 == 0 or x % 5 == 0 else 0 for x in range(1, 1000))
- Fishkins 13y agoYeah, a list comprehension is the easiest way to write it in any of the languages. I think it's a little clearer/shorter to do print sum(x for x in range(1, 1000) if x % 3 == 0 or x % 5 == 0)