请使用OrderDict类来重写这个程序,并确认输出的顺序与你在字典中添加键-值对的顺序一致。
from collections import OrderedDict
glossary = OrderedDict()
glossary['string'] = 'A series of characters.'
glossary['comment'] = 'A note in a program that the Python interpreter ignore.'
glossary['list'] = 'A collection of items in a particular order.'
glossary['loop'] = 'Work through a collection of items, one at a time.'
glossary['dictionary'] = 'A collection of key-value pairs.'
glossary['key'] = 'The first item in a key-value pair in a dictionary.'
glossary['valus'] = 'An item associated with a key in a dictionary.'
glossary['conditional test'] = 'A comparison between two values.'
glossary['float'] = 'A numerical value with a decimal compontent.'
glossary['boolean expression'] = 'An expression that evaluates to True or False.'
for word,definition in glossary.items():
print("\n" + word.title() + ": " + definition)
337

被折叠的 条评论
为什么被折叠?



