TypeError: can only concatenate list (not "tuple") to list

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Jan 4 21:35:03 EST 2010


On Tue, 05 Jan 2010 00:52:56 +0000, r0g wrote:

> I'd be strongly inclined to think the result would be the sequence on
> the left with the data from the second sequence appended to it. What's
> wrong with a little duck typing here eh?

That's not the existing behaviour. List concatenation doesn't mutate the 
left hand list, it creates a new list:


>>> L = [1, 2, 3]
>>> L2 = L + [4, 5, 6]
>>> L
[1, 2, 3]
>>> L2
[1, 2, 3, 4, 5, 6]


But if you insist on in-place modification, why do you prefer appending 
the right hand sequence to the left instead of prepending the left hand 
sequence to the right?



-- 
Steven



More information about the Python-list mailing list