[Tutor] repply

Sander Sweers sander.sweers at gmail.com
Sun Jan 4 14:31:16 CET 2009


On Sun, Jan 4, 2009 at 14:18, prasad rao <prasadaraon50 at gmail.com> wrote:
>>>> z=[]
>>>> for x in range(1000):
> if divmod(x,3)[1]==0:z.append(x)
> if divmod(x,5)[1]==0:z.append(x)
>>>> sum(set(z))
> 233168

This can be done in one line of python.

>>> sum([x for x in range(1000) if x %3 == 0 or x % 5 == 0])
233168

Greets
Sander


More information about the Tutor mailing list