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
On Apr 29, 9:32 am, Roy Smith <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > > > > > Mark Bryan Yu a écrit : > > > This set of codes works: > > > x = range(5) > > x.reverse() > > x > > > [4, 3, 2, 1, 0] > > > > But thi

Re: list.reverse()

2008-04-29 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Mark Bryan Yu a écrit : > > 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 > >

Re: list.reverse()

2008-04-29 Thread Bruno Desthuilliers
Mark Bryan Yu a écrit : 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 This works just as expected - at least for anyone having read the doc. Please explain this behavior. range(5) returns a list from 0 to 4 and

Re: list.reverse()

2008-04-28 Thread Arnaud Delobelle
Mark Bryan Yu <[EMAIL PROTECTED]> writes: > 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 revers

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