需要Python解决方案

时间:2017-10-28 22:20:45

标签: python python-2.7 python-3.x list

我有三个名单Teams = [T1,T2,T3,T4]和Nwins [10,12,10,5]的胜利数和他们进球的目标 GScored [33,34,22,28]。我希望根据他们的胜利数量找到赛季冠军,但是如果两支球队在赛季中获得相同的胜利,那么他们的得分数就会达到。类似地,获胜最少的一个将被降级,如果有两个,则得分最少的一个将被淘汰。我们将非常感谢您的帮助

2 个答案:

答案 0 :(得分:2)

winner = max(zip(Nwins, GScored, Teams))[2]

答案 1 :(得分:0)

Teams = ["T1","T2","T3","T4"]
NoWins = [10,0,10,5]
GScored = [33,34,22,28]

highestWins = max(NoWins)
if NoWins.count(highestWins) == 1:
   winner = Teams[NoWins.index(highestWins)] 
else:
   options = [g for i, g in enumerate(GScored) if NoWins[i] == highestWins]
   winner = [t for i, t in enumerate(Teams) if NoWins[i] == highestWins][options.index(max(options))]

lowestWins = min(NoWins)
if NoWins.count(lowestWins) == 1:
   relegated = Teams[NoWins.index(lowestWins)]
else:
   options = [g for i, g in enumerate(GScored) if NoWins[i] == lowestWins]
   relegated = [t for i, t in enumerate(Teams) if NoWins[i] == lowestWins][options.index(min(options))]

其中winner"T1"(我修改了您的示例),relegated"T2"

如果NoWins = [0, 2, 2, 2]GScored = [4, 4, 3, 3]winner"T2"relegated"T1"