Re: Add vs in-place add of str to list

2008-10-02 Thread rs387
On Oct 2, 3:50 pm, Mel <[EMAIL PROTECTED]> wrote: > rs387 wrote: > > I see. Do you know whether this is seen as a problem with the language > > design? > > No. OK, I get it now. I was assuming that the "+" could be implemented in terms of "+=" as follows: def add(x,y): temp = list(x) temp

Re: Add vs in-place add of str to list

2008-10-02 Thread Mel
rs387 wrote: > On Oct 2, 8:11 am, Erik Max Francis <[EMAIL PROTECTED]> wrote: >> It's because the `+=` operator is doing the equivalent of calling the >> `extend` method, which treats its argument as a generic sequence, and >> doesn't enforce type. > > I see. Do you know whether this is seen as a

Re: Add vs in-place add of str to list

2008-10-02 Thread rs387
On Oct 2, 8:11 am, Erik Max Francis <[EMAIL PROTECTED]> wrote: > It's because the `+=` operator is doing the equivalent of calling the > `extend` method, which treats its argument as a generic sequence, and > doesn't enforce type. I see. Do you know whether this is seen as a problem with the langu

Re: Add vs in-place add of str to list

2008-10-02 Thread Erik Max Francis
rs387 wrote: I'm trying to understand why it is that I can do a = [] a += 'stuff' a ['s', 't', 'u', 'f', 'f'] but not a = [] a = a + 'stuff' Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate list (not "str") to list Can someone explain the logic? W

Add vs in-place add of str to list

2008-10-02 Thread rs387
Hi I'm trying to understand why it is that I can do >>> a = [] >>> a += 'stuff' >>> a ['s', 't', 'u', 'f', 'f'] but not >>> a = [] >>> a = a + 'stuff' Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate list (not "str") to list Can someone explain the logi