Re: surprising += for lists

2012-11-04 Thread Terry Reedy
On 11/4/2012 7:45 AM, Dave Angel wrote: What I wonder about is why list's __add__ is so fussy. Guido's reason is that it is not clear what the types of [1,2] + (3,4), (1,2) + [3,4], [] + range(4), range(2) + [3,4], etcetera should be. Such mixtures may be bugs. Seq.__add__ exists to impleme

Re: surprising += for lists

2012-11-04 Thread Dave Angel
On 11/04/2012 06:57 AM, Ulrich Eckhardt wrote: > Hi everybody! > > I was just smacked by some very surprising Python 2.7 behaviour. I was > assembling some 2D points into a list: > > points = [] > points += (3, 5) > points += (4, 6) > > What I would have expected is to have [(3, 5), (4, 6)], in

Re: surprising += for lists

2012-11-04 Thread Alec Taylor
Quick aside, you can insert tuples without much effort: `points += ((3,5),)` And also that I can't do the reverse, i.e.: >>> foo = tuple() >>> foo += [5,6] Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate tuple (not "list") to tuple On Sun, Nov 4, 2012 at