Example of Python implementation of ordered dictionary method

黄舟
Release: 2017-10-04 09:25:55
Original
1488 people have browsed it

This article mainly introduces the simple implementation method of Python ordered dictionary, involving the related operation skills of Python using the OrderedDict method for dictionary sorting. Friends in need can refer to the following

The example of this article tells the Python ordered dictionary Simple implementation method. Share it with everyone for your reference, the details are as follows:

Code:


# -*- coding: UTF-8 -*-
import collections
print 'Regular dictionary:'
d = {}
d['a'] = 'A'
d['b'] = 'B'
d['c'] = 'C'
for k, v in d.items():
  print k, v
print '\nOrderedDict:'
d = collections.OrderedDict()
d['a'] = 'A'
d['b'] = 'B'
d['c'] = 'C'
for k, v in d.items():
  print k, v
Copy after login

Execution result:

The above is the detailed content of Example of Python implementation of ordered dictionary method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!