当前位置: 代码迷 >> 综合 >> python编程---example18
  详细解决方案

python编程---example18

热度:72   发布时间:2023-10-18 11:29:56.0

请使用OrderDict类来重写这个程序,并确认输出的顺序与你在字典中添加键-值对的顺序一致。 

from collections import OrderedDictglossary = 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)

 

  相关解决方案