我已经试过了:
players = ["P. V. Sindhu","Kim H-m","Cheung N Y","S Nehwal","S Jaquet","Nozomi Okuhara"]
match_details_combined = [{'Winner':'P. V. Sindhu','Loser':'Kim H-m','Matches':'21-16,21-14'},{'Winner':'P. V. Sindhu','Loser':'Cheung N Y','Matches':'19-21,23-21,21-17'},{'Winner':'S Nehwal','Loser':'S Jaquet','Matches':'21-11,21-12'},{'Winner':'Nozomi Okuhara','Loser':'S Nehwal','Matches':'12-21,21-17,21-10'},{'Winner':'Nozomi Okuhara','Loser':'P. V. Sindhu','Matches':'21-19,20-22,22-20'}]
print(match_details_combined)
player_details = {'P. V. Sindhu':{"SW":0,"SL":0,"GW":0,"GL":0},'Kim H-m':{'SW':0,'SL':0,'GW':0,'GL':0},'Cheung N Y':{'SW':0,'SL':0,'GW':0,'GL':0},'S Nehwal':{'SW':0,'SL':0,'GW':0,'GL':0},'S Jaquet':{'SW':0,'SL':0,'GW':0,'GL':0},'Nozomi Okuhara':{'SW':0,'SL':0,'GW':0,'GL':0}}
print(player_details)
for match in match_details_combined:
player_details[match['Winner']]['GW'] += 1
print(player_details)
for match in match_details_combined:
player_details[match['Loser']]['GL'] += 1
print(player_details)我的问题是:
将match_details中的值" matches“拆分为一个单独的匹配项列表。它应该看起来像这样:
"21-13,20-21" -> [[21,13],[20,21]] 确保拆分时,结果数是整数(使用类型转换)
发布于 2019-06-14 18:12:50
使用理解列表:
string = "21-13,20-21"
print([[int(y) for y in x.split('-')] for x in string.split(',')])输出:
[21,13,20,21]
https://stackoverflow.com/questions/56595949
复制相似问题