[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: list.reverse()
From:       blaine <frikker () gmail ! com>
Date:       2008-04-30 14:19:49
Message-ID: c6f9eb8e-5e29-4136-ab44-d32c49bd4e14 () w74g2000hsh ! googlegroups ! com
[Download RAW message or body]

On Apr 29, 8:51 pm, Roy Smith <r...@panix.com> wrote:
> In article
> <98c4ad4d-3174-40cd-b281-84e318d69...@24g2000hsh.googlegroups.com>,
>
>  blaine <frik...@gmail.com> 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: x.reverse() does the reverse and returns None.  or is
> > bitwise, so it sees that 'None' is not 'True' and then continues to
> > process the next operand, x.  x or'd with None will always be x (and x
> > has just been changed by the reverse()).  So you get the new value of
> > x :)
>
> Please don't do that in any code I have to read and understand.  Cool
> little tricks have no place in good code.
>
> >>> x = range(5)
> >>> x.reverse()
> >>> x
>
> [4, 3, 2, 1, 0]
>
> does the same thing, and it a lot easier to understand.  I buy my newlines
> in the big box at Costo, so I don't mind using a few extra ones here or
> there.

haha true - i usually don't use shortcuts, it kind of defeats the
purpose of the readability of python :)
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic