I have written four solutions to a problem(self explanatory) ,out of
them ,which one is the pythonic way of doing and
is there any other ways of solving it?
1.sum([i for i in range(1000) if i%3==0 or i%5==0])
2.gen=(i for i in range(1000))
sum([i for i in gen if i%3==0 or i%5==0])
3.sum(filter(lambda a:a%3==0 or a%5==0,range(1000)))
4.def generator(m):
count=0
while count<m:
if count%3==0 or count%5==0:
yield count
count+=1
sum([i for i in generator(1000)])
Regards,
~ Srini T
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers