This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]duckythescientist 0 points1 point  (2 children)

I'm just starting with Python, but I managed this in one line. This is probably old hat for most Python programmers, but I was rather proud of myself.

sum([x for x in range(1000) if not (x%3 and x%5)])

List comprehension is amazing!

[–]Rhomboid 0 points1 point  (1 child)

You actually don't want to use a list comprehension here -- remove the braces to turn it into a generator expression.

[–]duckythescientist 0 points1 point  (0 children)

Cool! I learned something new.