[Python] Dictionary derivation PEP 274--Dict comprehensions

Source: Internet
Author: User

I have met once before, this time in the group also encountered a few times a problem

A program written in python2.7. The dictionary derivation is used, but the server version number is python2.6 and cannot be executed.


Today checked the next about Dict comprehensions, in pep274 have clear explanation.

http://legacy.python.org/dev/peps/pep-0274/


Implementation
    All implementation details were resolved in the Python 2.7 and 3.0    time-frame.
This was added after 2.7.


What do we do with the 2.6 version number, which is useful for a loop to solve?

#表达式写法In [4]: print {I:CHR (65+i) for I in range (4)}{0: ' A ', 1: ' B ', 2: ' C ', 3: ' D '}
#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 '}

This article is derived from"Orangleliu Notebook" Blog. Be sure to keep this source http://blog.csdn.net/orangleliu/article/details/39895669


[Python] Dictionary derivation PEP 274--Dict comprehensions

Related Article

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.