Home >Backend Development >Python Tutorial >Example of Python implementation of ordered dictionary method
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!