码迷,mamicode.com
首页 > 编程语言 > 详细

python OrderDict

时间:2018-10-31 14:02:41      阅读:492      评论:0      收藏:0      [点我收藏+]

标签:code   ESS   nis   ems   pre   int   print   enc   RoCE   

# encoding: utf-8
import csv
import collections

d = {banana:3,apple:4,pear:1,orange:2}
print(d)
kd = collections.OrderedDict(sorted(d.items(),key = lambda t:t[0]))
print(key order)
print(kd)
vd = collections.OrderedDict(sorted(d.items(),key = lambda t:t[1]))
print(value order)
print(vd)
print(type(vd))
{‘banana‘: 3, ‘apple‘: 4, ‘pear‘: 1, ‘orange‘: 2}
key order
OrderedDict([(‘apple‘, 4), (‘banana‘, 3), (‘orange‘, 2), (‘pear‘, 1)])
value order
OrderedDict([(‘pear‘, 1), (‘orange‘, 2), (‘banana‘, 3), (‘apple‘, 4)])
<class ‘collections.OrderedDict‘>

Process finished with exit code 0

 

python OrderDict

标签:code   ESS   nis   ems   pre   int   print   enc   RoCE   

原文地址:https://www.cnblogs.com/xiaodebing/p/9882253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!