Python is readable

Arnaud Delobelle arnodel at gmail.com
Thu Mar 15 16:54:30 EDT 2012


On 15 March 2012 00:27, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle <arnodel at gmail.com> wrote:
>> I don't know this book and there may be a pedagogical reason for the
>> implementation you quote, but pairwise_sum is probably better
>> implemented in Python 3.X as:
>>
>> def pairwise_sum(list1, list2):
>>    return [x1 + x2 for x1, x2 in zip(list1, list2)]
>
> Okay, here's something for debate.
>
> Should the readability of a language be gauged on the basis of its
> standard library, or should you be comparing actual code?

But here's the code posted by the OP:

--- Python ---
def pairwise_sum(list1, list2):
   result = []
   for i in range(len(list1)):
       result.append(list1[i] + list2[i])
   return result
--- ---

The code I posted uses one builtin function (zip), the code posted by
the OP uses two (range and len).  Neither uses the standard library.

-- 
Arnaud



More information about the Python-list mailing list