使用Python 2.7。我與球隊的名字作爲鍵和運行的得分並允許每隊作爲值列表量的字典:迭代Python字典中對應於列表的鍵值
NL_East = {'Phillies': [645, 469], 'Braves': [599, 548], 'Mets': [653, 672]}
我想能夠養活字典成一個函數和遍歷每個團隊(關鍵)。
這是我正在使用的代碼。現在,我只能一起去團隊。我將如何迭代每個團隊併爲每個團隊打印預期的win_percentage?
def Pythag(league):
runs_scored = float(league['Phillies'][0])
runs_allowed = float(league['Phillies'][1])
win_percentage = round((runs_scored**2)/((runs_scored**2)+(runs_allowed**2))*1000)
print win_percentage
感謝您的任何幫助。
'dic.items()'... – JBernardo