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)
时间: 2024-10-10 17:58:40