Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread Alan Gauld via Tutor
On 27/07/17 03:22, C W wrote: > Thank you very much, Steve! > > I think I got it. To get help() on a method, you have to somehow invoke an > object first. Or just use the class. In Steven's examples he included list.sort. 'list' is the class name for a list. -- Alan G Author of the Learn to Pro

Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread C W
Thank you very much, Steve! I think I got it. To get help() on a method, you have to somehow invoke an object first. In your example, even an empty vector [] will do. Thanks! On Wed, Jul 26, 2017 at 10:16 PM, Steven D'Aprano wrote: > On Wed, Jul 26, 2017 at 10:03:59PM -0400, C W wrote: > > Th

Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread C W
Thank you very much, all! One other question: how do you look up a method? >help(sort) Traceback (most recent call last): File "", line 1, in help(sort) NameError: name 'sort' is not defined Back to function vs method, I came from R: aList = sort(aList) There was never aList.sort(),

Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread Steven D'Aprano
On Wed, Jul 26, 2017 at 10:03:59PM -0400, C W wrote: > Thank you very much, all! > > One other question: how do you look up a method? Any of these will work: help(list.sort) help([].sort) alist = [1, 2, 3, 99] help(alist.sort) -- Steve ___ Tutor

Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread Steven D'Aprano
On Wed, Jul 26, 2017 at 02:40:17PM -0400, C W wrote: > sorted(aList) > > [2, 3, 4, 5] sorted() makes a copy of whatever you give it, as a list, and sorts the copy. It doesn't have to be a list to start with: py> sorted("alphabet") ['a', 'a', 'b', 'e', 'h', 'l', 'p', 't'] > aList.sort() > aLis

Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread Alan Gauld via Tutor
On 26/07/17 19:40, C W wrote: > My understanding of each is: > 1) function(variable) is manipulating a vector, I can do bList = > sorted(aList) > 2) object.method() is permanently changing it, I don't even need to assign > it in #1. > > Why is there both? They do the same thing. As you have just

Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread Joel Goldstick
On Wed, Jul 26, 2017 at 2:40 PM, C W wrote: > Dear Python experts, > > I suppose I have the following Python code: > > aList = [3, 5, 2, 4] > > sorted(aList) > > [2, 3, 4, 5] > > aList.sort() > > aList > > [2, 3, 4, 5] > > My understanding of each is: > 1) function(variable) is manipulating a vec

[Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread C W
Dear Python experts, I suppose I have the following Python code: aList = [3, 5, 2, 4] sorted(aList) > [2, 3, 4, 5] aList.sort() aList > [2, 3, 4, 5] My understanding of each is: 1) function(variable) is manipulating a vector, I can do bList = sorted(aList) 2) object.method() is permanently ch