very good reasons?

Bernhard Herzog herzog at online.de
Thu Oct 5 18:06:18 EDT 2000


"Alex Martelli" <aleaxit at yahoo.com> writes:

> "Greg Ewing" <see at my.signature> wrote in message
> > If you really want an obfuscated way of writing
> > it, how about
> >
> > b = (a.sort(), a.reverse(), a)[-1]
> 
> Hmmm -- it does work with the current implementation
> (because sort is called first, then reverse) but I
> wonder whether it's guaranteed to keep working for
> all time.  Is left-to-right order of evaluation for
> tuple-constructor components guaranteed somewhere in
> the language specs?  A pointer would be welcome...

It seems so. From the reference manual:


   A parenthesized form is an optional expression list enclosed in
   parentheses:

       parenth_form:      "(" [expression_list] ")"

   A parenthesized expression list yields whatever that expression list
   yields: if the list contains at least one comma, it yields a tuple;
   otherwise, it yields the single expression that makes up the
   expression list.


and


       expression_list:      expression ("," expression)* [","]

   An expression (expression) list containing at least one comma yields
   a tuple. The length of the tuple is the number of expressions in the
   list. The expressions are evaluated from left to right.



-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list