2017-05-10 108 views
-3

這是我的字典
此時它正在更新。如何打印字典{}和'

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

請記住如何提問。 https://stackoverflow.com/help/how-to-ask – Robert

回答

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