My other pet python peeve - .sort(),.reverse(), etc. return None

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Fri, 17 Sep 1993 16:43:01 -0400

Silly me! My "Silly Python Trick #2" provides the obvious solution
to the general problem of wanting a procedure that also return an
updated object:

( thing.procedural_method() or thing ) ==> updated thing

as in:

>>> b = []
>>> for c in 'aBcDeFg' : Z = ( b.append(c) or b.reverse() or b )
... else: Z
...
['g', 'e', 'c', 'a', 'B', 'D', 'F']
>>>

BTW: The parends are necessary for: ( 1 or 2 )

>>> 1 or 2
Parsing error: file <stdin>, line 1:
1 or 2
^
SyntaxError: invalid syntax
>>> ( 1 or 2 )
1

Is this just an residue of the days when the parser had
to distinguish between boolean and binding "=", or does
it fulfill some other syntactical need ?

- Steve M.