Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: In Python, if you have x[0] = Dummy(), the list object x stores the Dummy instance itself. I think the above example gets to the source of my confusion. Clearly the instance remains accessible via x[0], but I somehow never thought of a specific list index as an obvious

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
First off, thanks for the detailed response! I had a few follow-up questions below, if you're willing to indulge. Feel free to direct me to RTM some books on C and the python source code, of course :) > Why? Because the designer of Python, Guido van Rossum, wanted it to be > possible, and he desi

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: But I think I see your point. The list object behaves the same as the objects stored inside the list. Er, surely not... the list object is a list, the objects inside the list are ints. They do not behave the same. > In other words, the list object is a reference to

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: Hi folks, I'm trying to gain a deeper understanding of why it's possible to modify list elements in-place *without* replacing them. For instance, why is the below possible? Why? Because the designer of Python, Guido van Rossum, wanted it to be possible, and he designed t

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
> > > Would you have the same question about what takes place here?: > > >>> list_ = [3,4,5] > >>> list_[1] = 10 > >>> list_ > [3, 10, 5] > >>> > > No surprise there. It's a familiar usage and it appears to be the canonical example (in textbooks/tuts) for demonstrating "in-place" object modificatio

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Richard D. Moores
On Thu, Nov 11, 2010 at 06:02, Serdar Tumgoren wrote: > Hi folks, > I'm trying to gain a deeper understanding of why it's possible to modify > list elements in-place *without* replacing them. For instance, why is the > below possible? > class Dummy(object): > ... pass > ... a = Dummy

[Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
Hi folks, I'm trying to gain a deeper understanding of why it's possible to modify list elements in-place *without* replacing them. For instance, why is the below possible? >>> class Dummy(object): ... pass ... >>> a = Dummy() >>> b = Dummy() >>> x = [a, b] # modify list elements in-place >>>