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])
On Tue, Feb 9, 2010 at 10:22 AM, Srinivas Reddy Thatiparthy
srinivas_thatipar...@akebonosoft.com wrote:
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
On Tue, Feb 9, 2010 at 10:22 AM, Srinivas Reddy Thatiparthy
srinivas_thatipar...@akebonosoft.com wrote:
1.sum([i for i in range(1000) if i%3==0 or i%5==0])
Slightly better would be:
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
Thanks for the replies and I avoid using lambdas..
Btw,Shall I avoid using filter and map ?
Because what ever filter and map do,I could seem to do the same with
Listcomprehensions..
Is there any situation in which they fare better than list
comprehensions?
Regards,
~ Srini T
filter, map (reduce, any, all) come from the world of Functional
Programming. For that matter list comprehension was borrowed from FP
(haskell).
I wont attempt to compare them as they cater to different needs. Yes, they
overlap in certain areas but I'd like to think of them as seperate assets
On 02/09/2010 10:37 AM, Anand Chitipothu wrote:
On Tue, Feb 9, 2010 at 10:22 AM, Srinivas Reddy Thatiparthy
[...snip...]
#1.
You can even remove the square brackets.
sum(i for i in range(1000) if i%3==0 or i%5==0)
Yes, you can but that doesn't necessarily mean it is better. Interestingly,
On Tue, Feb 9, 2010 at 10:52 AM, Srinivas Reddy Thatiparthy
srinivas_thatipar...@akebonosoft.com wrote:
Thanks for the replies and I avoid using lambdas..
Btw,Shall I avoid using filter and map ?
Because what ever filter and map do,I could seem to do the same with
Listcomprehensions..
Is
On Tue, Feb 9, 2010 at 1:03 PM, Dhananjay Nene dhananjay.n...@gmail.comwrote:
Anand Balachandran Pillai wrote:
On Tue, Feb 9, 2010 at 10:52 AM, Srinivas Reddy Thatiparthy
srinivas_thatipar...@akebonosoft.com wrote:
Thanks for the replies and I avoid using lambdas..
Btw,Shall I avoid