[BangPypers] which one is the best pythonic way .

2010-02-08 Thread Srinivas Reddy Thatiparthy
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])

Re: [BangPypers] which one is the best pythonic way .

2010-02-08 Thread Anand Chitipothu
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

Re: [BangPypers] which one is the best pythonic way .

2010-02-08 Thread Navin Kabra
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

Re: [BangPypers] which one is the best pythonic way .

2010-02-08 Thread Srinivas Reddy Thatiparthy
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

Re: [BangPypers] which one is the best pythonic way .

2010-02-08 Thread Jeffrey Jose
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

Re: [BangPypers] which one is the best pythonic way .

2010-02-08 Thread steve
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,

Re: [BangPypers] which one is the best pythonic way .

2010-02-08 Thread Anand Balachandran Pillai
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

Re: [BangPypers] which one is the best pythonic way .

2010-02-08 Thread Dhananjay Nene
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