Re: Why list.reverse() modifies the list, but name.replace() does not

2018-09-05 Thread Mark Lawrence
On 03/09/18 18:49, C W wrote: > Hello all, > > I am learning the basics of Python. How do I know when a method modifies > the original object, when it does not. I have to exmaples: > Example 1: >> L = [3, 6, 1,4] >> L.reverse() >> L > [4, 1, 6, 3] > This changes the original list. Lists are mutabl

Re: Why list.reverse() modifies the list, but name.replace() does not

2018-09-05 Thread Mike C
Mark Lawrence Sent: Monday, September 3, 2018 2:21:36 PM To: python-list@python.org Subject: Re: Why list.reverse() modifies the list, but name.replace() does not modify the string? On 03/09/18 18:49, C W wrote: > Hello all, > > I am learning the basics of Python. How do I know when a m

Re: Why list.reverse() modifies the list, but name.replace() does not

2018-09-05 Thread Chris Angelico
On Tue, Sep 4, 2018 at 3:49 AM, C W wrote: > Hello all, > > I am learning the basics of Python. How do I know when a method modifies > the original object, when it does not. I have to exmaples: > Example 1: >> L = [3, 6, 1,4] >> L.reverse() >> L > [4, 1, 6, 3] > This changes the original list. > >

Re: Why list.reverse() modifies the list, but name.replace() does not

2018-09-05 Thread Joel Goldstick
On Mon, Sep 3, 2018 at 1:50 PM C W wrote: > > Hello all, > > I am learning the basics of Python. How do I know when a method modifies > the original object, when it does not. I have to exmaples: > Example 1: > > L = [3, 6, 1,4] > > L.reverse() > > L > [4, 1, 6, 3] > This changes the original list.

Why list.reverse() modifies the list, but name.replace() does not

2018-09-05 Thread C W
Hello all, I am learning the basics of Python. How do I know when a method modifies the original object, when it does not. I have to exmaples: Example 1: > L = [3, 6, 1,4] > L.reverse() > L [4, 1, 6, 3] This changes the original list. Example 2: > name = "John Smith" > name.replace("J", j") > nam

Re: Why list.reverse() modifies the list, but name.replace() does not modify the string?

2018-09-03 Thread Mike C
f of Mark Lawrence Sent: Monday, September 3, 2018 2:21:36 PM To: python-list@python.org Subject: Re: Why list.reverse() modifies the list, but name.replace() does not modify the string? On 03/09/18 18:49, C W wrote: > Hello all, > > I am learning the basics of Python. How do I know

Re: Why list.reverse() modifies the list, but name.replace() does not modify the string?

2018-09-03 Thread Mark Lawrence
On 03/09/18 18:49, C W wrote: Hello all, I am learning the basics of Python. How do I know when a method modifies the original object, when it does not. I have to exmaples: Example 1: L = [3, 6, 1,4] L.reverse() L [4, 1, 6, 3] This changes the original list. Lists are mutable, i.e. can be ch

Re: Why list.reverse() modifies the list, but name.replace() does not modify the string?

2018-09-03 Thread Chris Angelico
On Tue, Sep 4, 2018 at 3:49 AM, C W wrote: > Hello all, > > I am learning the basics of Python. How do I know when a method modifies > the original object, when it does not. I have to exmaples: > Example 1: >> L = [3, 6, 1,4] >> L.reverse() >> L > [4, 1, 6, 3] > This changes the original list. > >

Re: Why list.reverse() modifies the list, but name.replace() does not modify the string?

2018-09-03 Thread Joel Goldstick
On Mon, Sep 3, 2018 at 1:50 PM C W wrote: > > Hello all, > > I am learning the basics of Python. How do I know when a method modifies > the original object, when it does not. I have to exmaples: > Example 1: > > L = [3, 6, 1,4] > > L.reverse() > > L > [4, 1, 6, 3] > This changes the original list.

Why list.reverse() modifies the list, but name.replace() does not modify the string?

2018-09-03 Thread C W
Hello all, I am learning the basics of Python. How do I know when a method modifies the original object, when it does not. I have to exmaples: Example 1: > L = [3, 6, 1,4] > L.reverse() > L [4, 1, 6, 3] This changes the original list. Example 2: > name = "John Smith" > name.replace("J", j") > nam

Re: list.reverse()

2008-04-30 Thread blaine
On Apr 29, 8:51 pm, Roy Smith <[EMAIL PROTECTED]> wrote: > In article > <[EMAIL PROTECTED]>, > > blaine <[EMAIL PROTECTED]> wrote: > > Check out this cool little trick I recently learned: > > >>> x=range(5) > > >>> x.reverse() or x > > [4, 3, 2, 1, 0] > > > Useful for returning lists that you need

Re: list.reverse()

2008-04-30 Thread Gabriel Genellina
En Tue, 29 Apr 2008 10:32:46 -0300, Roy Smith <[EMAIL PROTECTED]> escribió: What you want to do is look at the reversed() function. Not only does it return something (other than Null), but it is much faster because it doesn't have to store the reversed list anywhere. What it returns is an iter

Re: list.reverse()

2008-04-29 Thread Roy Smith
In article <[EMAIL PROTECTED]>, blaine <[EMAIL PROTECTED]> wrote: > Check out this cool little trick I recently learned: > >>> x=range(5) > >>> x.reverse() or x > [4, 3, 2, 1, 0] > > Useful for returning lists that you need to sort or reverse without > wasting that precious extra line :) > >

Re: list.reverse()

2008-04-29 Thread Carl Banks
On Apr 29, 9:32 am, Roy Smith <[EMAIL PROTECTED]> wrote: > The reasoning goes along the lines of, "reverse in place is an expensive > operation, so we don't want to make it too easy for people to do". At > least that's the gist of what I got out of the argument the many times it > has come up. Ex

Re: list.reverse()

2008-04-29 Thread Ivan Illarionov
On Tue, 29 Apr 2008 07:26:07 -0700, Paul McGuire wrote: > On Apr 28, 1:12 pm, Mark Bryan Yu <[EMAIL PROTECTED]> wrote: >> This set of codes works: >> >> >>> x = range(5) >> >>> x.reverse() >> >>> x >> >> [4, 3, 2, 1, 0] >> >> > You can also use list slicing to get a reversed list: > x = rang

Re: list.reverse()

2008-04-29 Thread Diez B. Roggisch
The reasoning goes along the lines of, "reverse in place is an expensive operation, so we don't want to make it too easy for people to do". At least that's the gist of what I got out of the argument the many times it has come up. It's not about the storage - it is about the in-place-modifi

Re: list.reverse()

2008-04-29 Thread Paul McGuire
On Apr 28, 1:12 pm, Mark Bryan Yu <[EMAIL PROTECTED]> wrote: > This set of codes works: > > >>> x = range(5) > >>> x.reverse() > >>> x > > [4, 3, 2, 1, 0] > You can also use list slicing to get a reversed list: >>> x = range(5) >>> x [0, 1, 2, 3, 4] >>> x[::-1] [4, 3, 2, 1, 0] -- Paul -- http://

Re: list.reverse()

2008-04-29 Thread Bruno Desthuilliers
Roy Smith a écrit : (snip) The reasoning goes along the lines of, "reverse in place is an expensive operation, so we don't want to make it too easy for people to do". At least that's the gist of what I got out of the argument the many times it has come up. IIRC, it's more along the line of

Re: list.reverse()

2008-04-29 Thread blaine
at least for anyone having read the doc. > > > > Please explain this behavior. range(5) returns a list from 0 to 4 and > > > reverse just reverses the items on the list that is returned by > > > range(5). Why is x None (null)? > > > Because that's what list

Re: list.reverse()

2008-04-29 Thread Roy Smith
t; > > But this doesn't: > > > >>>> x = range(5).reverse() > >>>> print x > > None > > This works just as expected - at least for anyone having read the doc. > > > Please explain this behavior. range(5) returns a list from

Re: list.reverse()

2008-04-29 Thread Bruno Desthuilliers
to 4 and reverse just reverses the items on the list that is returned by range(5). Why is x None (null)? Because that's what list.reverse() returns. Call it a wart if you want (FWIW, I do), but at least that's well documented. -- http://mail.python.org/mailman/listinfo/python-list

Re: list.reverse()

2008-04-28 Thread Arnaud Delobelle
one > > Please explain this behavior. range(5) returns a list from 0 to 4 and > reverse just reverses the items on the list that is returned by > range(5). Why is x None (null)? have you tried typing help(list.reverse) at the interactive prompt? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: list.reverse()

2008-04-28 Thread Gary Herron
Mark Bryan Yu wrote: This set of codes works: x = range(5) x.reverse() x [4, 3, 2, 1, 0] But this doesn't: x = range(5).reverse() print x None Please explain this behavior. range(5) returns a list from 0 to 4 and reverse just reverses the items on the list that is

list.reverse()

2008-04-28 Thread Mark Bryan Yu
This set of codes works: >>> x = range(5) >>> x.reverse() >>> x [4, 3, 2, 1, 0] But this doesn't: >>> x = range(5).reverse() >>> print x None Please explain this behavior. range(5) returns a list from 0 to 4 and reverse just reverses the items on the list that is returned by range(5). Why is x