list.reverse()
blaine
frikker at gmail.com
Wed Apr 30 10:19:49 EDT 2008
On Apr 29, 8:51 pm, Roy Smith <r... at panix.com> wrote:
> In article
> <98c4ad4d-3174-40cd-b281-84e318d69... at 24g2000hsh.googlegroups.com>,
>
> blaine <frik... at 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 :)
More information about the Python-list
mailing list