Re: [newbie] A question about lists and strings

2012-08-10 Thread Rotwang
On 10/08/2012 10:59, Peter Otten wrote: [...] If you have understood the above here's a little brain teaser: a = ([1,2,3],) a[0] += [4, 5] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment a[0] What are the contents of a[

Re: [newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen
Am 10.08.2012 12:56, schrieb Roman Vashkevich: I am not sure I understand your question. Can you rephrase it or make it more explicit? I have just detailed my problem and Dave Angel has shown how to solve it properly. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] A question about lists and strings

2012-08-10 Thread Chris Angelico
On Fri, Aug 10, 2012 at 8:56 PM, Dave Angel wrote: >> On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel wrote: >>> But if you said c=651 and d=651, you'd have two >>> objects, and the two names would be bound to different objects, with >>> different ids. >> To be more accurate, you *may* have two diff

Re: [newbie] A question about lists and strings

2012-08-10 Thread Roman Vashkevich
10.08.2012, в 14:12, Mok-Kong Shen написал(а): > Am 10.08.2012 11:48, schrieb Roman Vashkevich: >> [snip] > >The function It takes list by reference and creates a new local > > str. When it's called with listb and strb arguments, listb is passed > > by reference and mutated. A string "sss" is

Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 06:48 AM, Mok-Kong Shen wrote: > Am 10.08.2012 12:40, schrieb Chris Angelico: > >> But it's probably worth thinking about exactly why you're wanting to >> change that string, and what you're really looking to accomplish. >> There may well be a better way. > > My problem is the followi

Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 06:37 AM, Chris Angelico wrote: > On Fri, Aug 10, 2012 at 8:12 PM, Mok-Kong Shen > wrote: >> Thanks for the explanation of the output obtained. But this means >> nonetheless that parameters of types lists and strings are dealt with >> in "inherently" (semantically) different ways by

Re: [newbie] A question about lists and strings

2012-08-10 Thread Roman Vashkevich
10.08.2012, в 14:12, Mok-Kong Shen написал(а): > Am 10.08.2012 11:48, schrieb Roman Vashkevich: >> [snip] > >The function It takes list by reference and creates a new local > > str. When it's called with listb and strb arguments, listb is passed > > by reference and mutated. A string "sss" is

Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 06:31 AM, Mok-Kong Shen wrote: > Am 10.08.2012 12:07, schrieb Dave Angel: > [snip] >> At this point, in top-level code, the listb object has been modified, >> and the strb one has not; it still is bound to the old value. > > This means there is no way of modifying a string at the top

Re: [newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen
Am 10.08.2012 12:40, schrieb Chris Angelico: But it's probably worth thinking about exactly why you're wanting to change that string, and what you're really looking to accomplish. There may well be a better way. My problem is the following: I have at top level 3 lists and 3 strings: lista, lis

Re: [newbie] A question about lists and strings

2012-08-10 Thread Chris Angelico
On Fri, Aug 10, 2012 at 8:31 PM, Mok-Kong Shen wrote: > This means there is no way of modifying a string at the top level > via a function, excepting through returning a new value and assigning > that to the string name at the top level. Please again correct me, if > I am wrong. Yes, but you can

Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 06:12 AM, Mok-Kong Shen wrote: > Am 10.08.2012 11:48, schrieb Roman Vashkevich: >> [snip] > >The function It takes list by reference and creates a new local > > str. When it's called with listb and strb arguments, listb is passed > > by reference and mutated. A string "sss" is co

Re: [newbie] A question about lists and strings

2012-08-10 Thread Chris Angelico
On Fri, Aug 10, 2012 at 8:12 PM, Mok-Kong Shen wrote: > Thanks for the explanation of the output obtained. But this means > nonetheless that parameters of types lists and strings are dealt with > in "inherently" (semantically) different ways by Python, right? It's nothing to do with parameters, b

Re: [newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen
Am 10.08.2012 12:07, schrieb Dave Angel: [snip] At this point, in top-level code, the listb object has been modified, and the strb one has not; it still is bound to the old value. This means there is no way of modifying a string at the top level via a function, excepting through returning a ne

Re: [newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen
Am 10.08.2012 11:48, schrieb Roman Vashkevich: [snip] >The function It takes list by reference and creates a new local > str. When it's called with listb and strb arguments, listb is passed > by reference and mutated. A string "sss" is concatenated with an > empty local str. Nothing more ha

Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 05:19 AM, Mok-Kong Shen wrote: > > In an earlier question about lists, I was told about the issue of > creation of local names in a function. However, I still can't > understand why the program below outputs: > > [999] sss > [999] > > and not two identical lines of output. For both op

Re: [newbie] A question about lists and strings

2012-08-10 Thread Peter Otten
Mok-Kong Shen wrote: > > In an earlier question about lists, I was told about the issue of > creation of local names in a function. However, I still can't > understand why the program below outputs: > > [999] sss > [999] > > and not two identical lines of output. For both operators "+=" should

Re: [newbie] A question about lists and strings

2012-08-10 Thread Roman Vashkevich
10.08.2012, в 13:28, Roman Vashkevich написал(а): > 10.08.2012, в 13:19, Mok-Kong Shen написал(а): > >> >> In an earlier question about lists, I was told about the issue of >> creation of local names in a function. However, I still can't >> understand why the program below outputs: >> >> [999]

Re: [newbie] A question about lists and strings

2012-08-10 Thread Roman Vashkevich
10.08.2012, в 13:19, Mok-Kong Shen написал(а): > > In an earlier question about lists, I was told about the issue of > creation of local names in a function. However, I still can't > understand why the program below outputs: > > [999] sss > [999] > > and not two identical lines of output. For b

[newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen
In an earlier question about lists, I was told about the issue of creation of local names in a function. However, I still can't understand why the program below outputs: [999] sss [999] and not two identical lines of output. For both operators "+=" should anyway work in similar manner in the fu