Skip to content
Advertisement

Grouping speaker dialogue in a written transcript

I have a txt file for a transcript. Example content:

JavaScript

I would like to write some python code that will give the following output:

JavaScript

So if Travis de Ronde is talking, for example, I want all of his dialogue to be on one “line” under his name until he is finished speaking or another speaker begins talking.

Advertisement

Answer

This is a very good job for itertools.groupby, not regular expressions:

JavaScript

This yields

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement