I have encountered a time before, this period in the group also encountered a few times a problem
A program written in python2.7 uses dictionary derivation, but the server version is python2.6 and cannot be run.
Today I checked the dict comprehensions, there is a clear explanation in pep274.
http://legacy.python.org/dev/peps/pep-0274/
Copy Code code as follows:
Implementation
All implementation details were resolved in the Python 2.7 and 3.0
Time-frame.
This is only added after 2.7.
In the 2.6 version of how we use it, in fact, with a For loop to solve the good
Copy Code code as follows:
#表达式写法
In [4]: print {I:CHR (65+i) for I in range (4)}
{0: ' A ', 1: ' B ', 2: ' C ', 3: ' D '}
Copy Code code as follows:
#for循环写法
In [5]: D = {}
In [6]: For I in range (4):
...: d[i] = Chr (65+i)
...:
In [7]: Print D
{0: ' A ', 1: ' B ', 2: ' C ', 3: ' D '}