使用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