我卡上做文章,試圖重新格式化的字典如何格式化的字典蟒蛇
這裏是我的代碼,該代碼編寫字典:
deLimit = "**"
hashKey = item1 +deLimit+ item2 +deLimit+ item3 +deLimit+ item4
mydict[hashKey] = {
「key」: currentTotal + 1
}
with open(file,’a’) as newfile:
print 「heading1 heading2 heading3 heading4 heading5」
for key, val in myDict.iteritems():
print(repr((key.split('**'), val)))
結果:
heading1 heading2 heading3 heading4 heading5
([‘item1’, ‘item2’, ‘item3’, ‘item4’], {‘key’: 1})
([‘item1’, ‘item2’, ‘item3’, ‘item4’], {‘key’: 1})
([‘item1’, ‘item2’, ‘item3’, ‘item4’], {‘key’: 1})
我知道再版讓我的字典的一個很好的格式。但是,我如何重新格式化輸出?
我正在尋找實現的是:
heading1 heading2 heading3 heading4 heading5
item1 item2 item3 item4 keyValue
item1 item2 item3 item4 keyValue
item1 item2 item3 item4 keyValue
item1 item2 item3 item4 keyValue
item1 item2 item3 item4 keyValue
…
但我不知道如何重新格式化此輸出
([‘item1’, ‘item2’, ‘item3’, ‘item4’], {‘key’: 1})
感謝
你不知道。您迭代結構並生成您自己的輸出。 –
「myDict」的結構是什麼? – Rohanil
你的「myDict」是什麼樣的? –