我有以下字符串。我正在将它转换为字典,但我检索的输出不是预期的输出。
result = ' Thomas got 99 and James got 95, Gerrard got 84 and Tim got 21'
mydict = dict((k.strip(), v.strip()) for k,v in
(item.split('and') for item in result.split(',')))
print(mydict)
output is: {'Thomas got 99': 'James got 95', 'Gerrard got 84': 'Tim got 21'}
我希望预期的输出如下所示
output is:{'Thomas': '99', 'James': '95', 'Gerrard': '84', 'Tim': '21'}
谢谢
繁花如伊
蝴蝶不菲
红糖糍粑
相关分类