在我的项目中,我正在收集UFC网站上每个UFC运动员的总胜利、总损失和总平局.
这是我代码的一部分,因为我希望分别go 掉总胜利、总失败和总平局:
import re
record = "10-7-3 (W-L-D)" #W = wins, L= Loss, D= Draws
char = "-"
record+="-"
totalwins = ""
totalloss = ""
totaldraws = ""
correctRecord = re.findall('\[[^\]]*\]|\([^\)]*\)|\"[^\"]*\"|\S+',record)[0]
print("The correct record per fighter is:", correctRecord)
totaldash = 0
for i in range(len(correctRecord)):
if(record[i] == char):
totaldash+=1
if totaldash == 1:
print("The total wins", totalwins)
totalwins =""
elif totaldash ==2:
print("The total losses ", totalwins)
totalwins=""
elif totaldash ==3:
print("The total draws ", totalwins)
elif (correctRecord[i] !=char):
totalwins +=correctRecord[i]
结果如下:
The correct record per fighter is: 10-7-3
The total wins 10
The total losses 7
问题是,我不能说出总的平局.我也try 了使用条带法,但没有效果:
correctRecord= str(record.split(separator, 1)[0])