[Python-3000] Python 3000 Status Update (Long!)

Nicko van Someren nicko at nicko.org
Sat Jun 23 10:12:30 CEST 2007


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




More information about the Python-3000 mailing list