Evaluation order of dictionary literals
dictionary, python
Solution
This section of the reference manual documents the order, but claims it is different than what you are seeing: http://docs.python.org/2/reference/expressions.html#evaluation-order
In the following lines, expressions will be evaluated in the arithmetic order of their suffixes:
expr1, expr2, expr3, expr4
(expr1, expr2, expr3, expr4)
{expr1: expr2, expr3: expr4}
expr1 + expr2 * (expr3 - expr4)
expr1(expr2, expr3, *expr4, **expr5)
expr3, expr4 = expr1, expr2
And there is an open bug against the implementation about it: Evaluation order of dictionary display is different from reference manual.
Problem
``` def key(): print 'key' def val(): print 'val' {key() : val()} ``` prints `val, key`, i.e. the value is evaluated first. Is this behaviour - consistent across python versions and implementations? - documented anywhere? (http://docs.python.org/2/reference/expressions.html#dictionary-displays says nothing)