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

2010-02-09 Thread Anand Balachandran Pillai
On Tue, Feb 9, 2010 at 1:11 PM, Dhananjay Nene wrote: > On Tue, Feb 9, 2010 at 1:03 PM, Dhananjay Nene >wrote: > > > > > > > Interestingly in my computations the second approach (zip) is about 35% > > slower (as measured over 5 runs of 1M iterations each) than the first one > > (map/lambda). I b

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 wrote: > Anand Balachandran Pillai wrote: > > On Tue, Feb 9, 2010 at 10:52 AM, Srinivas Reddy Thatiparthy > wrote: > > > > Thanks for the replies and I avoid using lambdas.. > Btw,Shall I avoid using filter and map ? > Because what ever filter and

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

2010-02-08 Thread Srinivas Reddy Thatiparthy
>> But practicality beats purity. Given a choice, I will always use the latter instead of the former, irrespective of the "elegance", which is questionable and subjective anyway :) Shall I say,Go with your personal preference in personal projects,provided milliseconds performance is not a constra

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..

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, so

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 suit

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 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 g

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 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 range(1000) if i%3==0 or i%5==0]) > > 2.g

[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]) 3.s