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

python之OrderedDict类

时间:2017-07-23 19:47:22      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:键值   不同的   style   print   span   ict   import   tle   class   

 1 # OrderedDict类使用举例
 2 # OrderedDict类的使用与字典相似,不同的是OrderedDict类会记录键值对的添加顺序
 3 from collections import OrderedDict
 4 
 5 hoppys = OrderedDict()
 6 hoppys[‘mike‘] = ‘swim‘
 7 hoppys[‘tom‘] = ‘reading‘
 8 hoppys[‘lily‘] = ‘singing‘
 9 
10 print(hoppys)
11 print(‘Tom的爱好是:‘ + hoppys[‘tom‘])
12 
13 for name, hoppy in hoppys.items():
14     print(‘-‘, name.title(), hoppy)

 

python之OrderedDict类

标签:键值   不同的   style   print   span   ict   import   tle   class   

原文地址:http://www.cnblogs.com/gongxr/p/7225461.html

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