On 21 Jun 2007, at 21:21, Bill Janssen wrote:

>>> It should amount to "map(+, operands)".
>>
>> Or, to be pedantic, this:
>>
>>      reduce(lambda x, y: x.__add__(y), operands)
>
> Don't you mean:
>
>    reduce(lambda x, y:  x.__add__(y), operands[1:], operands[0])

In the absence of a "start" value reduce "does the right thing", so  
you don't need to do that.  My original post was asking for sum to  
behave as Joel wrote.  At the moment sum is more like:
        def sum(operands, start=0):
                return reduce(lambda x,y: x+y, operands, start)
Since the start value defaults to 0, if you don't specify a start  
value and your items can't be added to zero you run into a problem.   
I was proposing something that behaved more like:
        def sum(operands, start=None):
                if start is None:
                        operands , start = operands[1:], operands[0]
                return reduce(lambda x,y: x+y, operands, start)

The best argument against this so far however is the one from Gareth  
about what type is returned if no start value is given and the list  
is also empty.  Unless one is happy with the idea that sum([]) ==  
None then I concede that the current behaviour is probably the best  
compromise.  That said, I still think that the special case rejection  
of strings is ugly!

        Cheers,
                Nicko


_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to