[BangPypers] which is better solution of the question
pradeep at btbytes.com
Tue Jun 16 17:58:32 CEST 2009
On Tue, Jun 16, 2009 at 10:42 AM, Pradeep Gowda<pradeep at btbytes.com> wrote:
> On Tue, Jun 16, 2009 at 9:52 AM, Abhishek
> Tiwari<tiwariabhishekin at gmail.com> wrote:
>> I would like to know which method is better and why?
> Better for what purpose?
> 1. speed of execution?
> 2. elegance?
The list comprehension solution is slightly more approachable
(many are not familiar with the zip() function. I don't use zip on the
first go, if at all.)
The zip solution is succinct.
Also, by the virtue of being a built-in function zip() should be
faster than the second approach.
I wrote a script to test this hypothesis : http://dpaste.com/55994/
The zip() version is 100 times faster on average than the other solution.
# avg time taken for ans1 : 0.0035585308075
# avg time taken for ans2 : 0.306885209084
(averaged over 50 runs)
More information about the BangPypers