Home >Backend Development >Python Tutorial >Example of Python implementation of ordered dictionary method

Example of Python implementation of ordered dictionary method

黄舟
黄舟Original
2017-10-04 09:25:551505browse

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

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!

Statement:
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