[issue40088] list.reverse(): slow sublist reverse

2020-03-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Thanks for the suggestion, but the need isn't common enough to warrant an API expansion. If this were a popular operation, it might be worth optimizing, the need almost never arises. -- resolution: -> rejected stage: -> resolved status: open

[issue40088] list.reverse(): slow sublist reverse

2020-03-28 Thread Terry J. Reedy
Terry J. Reedy added the comment: The previous issue was also about .sort and Raymond's rejection was mostly about .sort. I will let him comment about whether the speedup moves him at all. Yury, please say something about your use case. -- nosy: +terry.reedy

[issue40088] list.reverse(): slow sublist reverse

2020-03-27 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: This looks like a duplicate of https://bugs.python.org/issue1491804 -- nosy: +rhettinger, xtreak ___ Python tracker ___

[issue40088] list.reverse(): slow sublist reverse

2020-03-27 Thread Yury Norov
/19181 Thanks, Yury -- components: C API, Interpreter Core messages: 365147 nosy: Yury priority: normal pull_requests: 18548 severity: normal status: open title: list.reverse(): slow sublist reverse versions: Python 3.9 ___ Python tracker <ht

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

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

2018-09-05 Thread Mike C
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 method

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

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") >

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

2018-09-03 Thread Mike C
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 when

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

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

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") >

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

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 to sort or reverse

Re: list.reverse()

2008-04-29 Thread Bruno Desthuilliers
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-29 Thread Roy Smith
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.reverse() returns. Call it a wart if you want (FWIW, I do

Re: list.reverse()

2008-04-29 Thread blaine
list.reverse() returns. Call it a wart if you want (FWIW, I do), but at least that's well documented. 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

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 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 --

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

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 = range(5) x [0, 1, 2, 3, 4] x[::-1]

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. Except

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 :) What it does:

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 None (null)?

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

Re: list.reverse()

2008-04-28 Thread Arnaud Delobelle
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