-2

I am analyzing a text file filled with monologues and I would like to create a separate text file composed of monologues from a single character.

Here's an example:

PERSON A:

Hi

PERSON B:

Hello

My goal is to slice all monologues from Person A into a new text. I've been battling with this for hours but I have no clue. Any help?

xlvs
  • 1
  • 3

1 Answers1

1

Think about which character or string separates the speeches of the persons. Use the split function and keep the delimiter. See https://docs.python.org/3/library/stdtypes.html#str.split and In Python, how do I split a string and keep the separators?. Then think about how you can identify the speeches of the persons in the result of the split function. When you can identify them separate them and write them to a file.

Osvald Laurits
  • 1,228
  • 2
  • 17
  • 32