A discussion with a friend led to the following realization:
>>> import dis
>>> i = lambda n: n*24*60*60
>>> dis.dis(i)
1 0 LOAD_FAST 0 (n)
3 LOAD_CONST 1 (24)
6 BINARY_MULTIPLY
7 LOAD_CONST 2 (60)
10 BINARY_MULTIPLY
11 LOAD_CONST 2 (60)
14 BINARY_MULTIPLY
15 RETURN_VALUE
>>> k = lambda n: 24*60*60*n
>>> dis.dis(k)
1 0 LOAD_CONST 4 (86400)
3 LOAD_FAST 0 (n)
6 BINARY_MULTIPLY
7 RETURN_VALUE
The second example is clearly more efficient simply by reducing the number of instructions.
My question is, is there a name for this optimization, and why doesn't it happen in the first example?
Also, I'm not sure if this is a duplicate of Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)? ; if it is please explain a bit further as it applies to Python.