Skip to content
Advertisement

Formatting a list of sentences extracted from text

I am trying to format a list neatly that I have extracted using regex. I would like to have each sentence in its own line and remove the n characters:

JavaScript

Image of current output:

enter image description here

Advertisement

Answer

From OP’s image, text_1 is a list of strings. To remove the newline n characters from a string, you can use the string’s replace method. To print each newline-removed sentence on its own line, you can use a simple for loop. Keeping the rest of the code intact, replace print(sentences) with:

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