我有一根这样的绳子
b'***************** Winner Prediction *****************\nDate: 2019-08-27 07:00:00\nRace Key: 190827082808\nTrack Name: Mornington\nPosition Number: 8\nName: CONSIDERING\nFinal Odds: 17.3\nPool Final: 37824.7\n'
在Python中,我想将这个字符串拆分为如下变量:
Date =
Race_Key =
Track_Name =
Name =
Final_Odds =
Pool_Final =
但是,字符串的格式总是相同的,但是值总是不同的,例如,名称中可能有两个单词,因此需要处理所有情况。你知道吗
我试过:
s = re.split(r'[.?!:]+', pred0)
def search(word, sentences):
return [i for i in sentences if re.search(r'\b%s\b' % word, i)]
但是那里没有运气。你知道吗
您可以使用以下选项:
这将返回(作为示例输入):
您可以拆分字符串并将其解析为一个dict,如下所示:
结果:
也许你可以试试这个:
相关问题 更多 >
编程相关推荐