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: 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.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to