这是我的词典
此时它正在更新。
DictDestination.update({(listDestinations[intCount]): [(" Discount of ${0:.2f}".format(intDiscount)), ("Thats {0:.2f}% off".format(intPercentage)), ("The saver type is {}".format(strSaverType)), ("Your original price was ${0:.2f}".format(intOriginal)), ("Your new price is ${0:.2f}".format(intNew))]})
到目前为止,我正在使用pprint模块打印它,我就是这样出来的。
{ 'Auckland': [ ' Discount of $1.00',
'Thats 1.00% off',
'The saver type is Quick Saver',
'Your original price was $1.01',
'Your new price is $0.01'],
'Rotarua': [ ' Discount of $1.00',
'Thats 1.00% off',
'The saver type is Quick Saver',
'Your original price was $1.01',
'Your new price is $0.01'],
'Wellington': [ ' Discount of $1.00',
'Thats 1.00% off',
'The saver type is Quick Saver',
'Your original price was $1.01',
'Your new price is $0.01']}
但是我想要它出来像这样
Auckland : Discount of $1.0
Thats 1.00% off
The saver type is Quick Saver
Your original price was $1.01
Your new price is $0.01
Rotarua : Discount of $1.00
hats 1.00% off
The saver type is Quick Saver
Your original price was $1.01
Your new price is $0.01
Wellington : Discount of $1.00
That's 1.00% off
The saver type is Quick Saver
Your original price was $1.01
Your new price is $0.01
我不知道您是否可以使用任何类型的模块,但我们将非常感谢任何帮助。
答案 0 :(得分:0)
您可以使用for
循环遍历字典中的项目,并使用print
函数使用所需的格式打印生成的键和值。
for key, value in dictionary.items():
#do the formatting to print the key/value
#A loop for the items in embedded lists
for list_item in value:
#print stuff as needed here
pass