Re: [Tutor] 'in-place' methods

2006-02-19 Thread Alan Gauld
> [1] Every couple of years, I decide to learn Java, and start going through > a book -- usually the same book. It doesn't go long before I say to my > self, "Gosh, why would I ever want to program this language, anyway?" I've taught myself Java three times(*), first from the O'Reilly Nutshell b

Re: [Tutor] 'in-place' methods

2006-02-18 Thread Terry Carroll
On Sun, 19 Feb 2006, Alan Gauld wrote: > But don't even joke about it. It is pretty cringe-worthy, isn't it? > Decorators are bad enough, no more line noise in Python. I was actually kind of sad to see that added. It struck me as the first grafted-on feature of Python that *felt* grafted-on.

Re: [Tutor] 'in-place' methods

2006-02-18 Thread Alan Gauld
>> Ruby has an interesting approach to this - the names of mutating methods >> end with !. So it would be list.sort!() which gives a strong cue to what > > What a great idea! Hmm.. maybe Python could do this, too; and use some > other characters like $, @ and % to indicate if a name is a reference

Re: [Tutor] 'in-place' methods

2006-02-18 Thread Terry Carroll
On Fri, 17 Feb 2006, Kent Johnson wrote: > Ruby has an interesting approach to this - the names of mutating methods > end with !. So it would be list.sort!() which gives a strong cue to what > is happening. What a great idea! Hmm.. maybe Python could do this, too; and use some other characters

Re: [Tutor] 'in-place' methods

2006-02-18 Thread w chun
> Perhaps you've seen this already, but since you are wrapping the print > in a function, I suspect you want the original list to be unmodified. > Thus, compare: > > >>> def sort_print1(a_list): > a_list.sort() > print a_list > > > >>> def sort_print2(a_list): > t = list(a

Re: [Tutor] 'in-place' methods

2006-02-18 Thread Brian van den Broek
Michael Broe said unto the world upon 17/02/06 03:57 PM: > Second question. Do I really have to write the sort_print() function > like this: > > def sort_print(L): > L.sort() > print L > > i.e. first perform the operation in-place, then pass the variable? Is > this the id

Re: [Tutor] 'in-place' methods

2006-02-17 Thread Kent Johnson
Michael Broe wrote: > I think I understand this sorting-a-list 'in place' stuff, and things > of that kind (reversing for example); but I am finding it very > difficult to get used to, since sorting a list doesn't return the > sorted list as a value, but simply does the work as a side effect.

Re: [Tutor] 'in-place' methods

2006-02-17 Thread Alan Gauld
> is, I think you've hit on the answer: the default, if you will, is to > perform operations in-place, to avoid the necessity of reassigning a > list to it's sorted version, to give one example. But that isn't necessary, you could just return a reference to the sorted list, that is: x = L.s

Re: [Tutor] 'in-place' methods

2006-02-17 Thread Alan Gauld
>I think I understand this sorting-a-list 'in place' stuff, and things > of that kind (reversing for example); but I am finding it very > difficult to get used to, since sorting a list doesn't return the > sorted list as a value, but simply does the work as a side effect. If its any consola

Re: [Tutor] 'in-place' methods

2006-02-17 Thread w chun
hi mike, welcome to python. :-) your query is quite common amongst beginners, and i have actually spend some time on this topic in my courses. On 2/17/06, Michael Broe <[EMAIL PROTECTED]> wrote: > I think I understand this sorting-a-list 'in place' stuff, and things > of that kind (reversing fo

Re: [Tutor] 'in-place' methods

2006-02-17 Thread Orri Ganel
Michael Broe wrote: >I think I understand this sorting-a-list 'in place' stuff, and things >of that kind (reversing for example); but I am finding it very >difficult to get used to, since sorting a list doesn't return the >sorted list as a value, but simply does the work as a side effect. >

[Tutor] 'in-place' methods

2006-02-17 Thread Michael Broe
I think I understand this sorting-a-list 'in place' stuff, and things of that kind (reversing for example); but I am finding it very difficult to get used to, since sorting a list doesn't return the sorted list as a value, but simply does the work as a side effect. The place where it really