希望这是一个非常直截了当的问题。我有一个成绩单,我试图将其分成每个发言者的块。我目前拥有的代码是;
text = '''
Speaker 1: hello there
this is some text.
Speaker 2: hello there,
this is also some text.
'''
a = text.split('\nSpeaker')
这会按照我的意愿拆分文本,但是我错过了第二个话语中的“演讲者”标识符。为了识别目的,我需要保留它。具体来说,我试图获得的是类似于以下的结果;
['Speaker 1: hello there\n\nI am checking to see if this works. \n', ' Speaker2:
Hopefully it will, \n\nit seems pretty straightforward.\n']
欢迎任何建议
谢谢