list.reverse()
Roy Smith
roy at panix.com
Tue Apr 29 20:51:27 EDT 2008
In article
<98c4ad4d-3174-40cd-b281-84e318d699d3 at 24g2000hsh.googlegroups.com>,
blaine <frikker 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.
More information about the Python-list
mailing list