Implementing dictionary derivation in Python2.6 version PEP 274

Source: Internet
Author: User
Tags chr

This article mainly introduces the Python2.6 version of the implementation of dictionary derivation PEP 274 (Dict comprehensions), this paper gives the expression and for-loop writing two ways to achieve character derivation, the need for friends can refer to the following

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.

The code is as follows:


All implementation details were resolved in the Python 2.7 and 3.0


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

The code is as follows:


In [4]: print {I:CHR (65+i) for I in range (4)}

{0: ' A ', 1: ' B ', 2: ' C ', 3: ' D '}

The code is as follows:


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 '}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.