For example:
my_string = "hi how are you?/nIs everything ok?/nAre you happy?"
I need to make a list containing all the indexes of the newline - (/n). How can i do it ?
For example:
my_string = "hi how are you?/nIs everything ok?/nAre you happy?"
I need to make a list containing all the indexes of the newline - (/n). How can i do it ?
import re
my_string = "hi how are you?/nIs everything ok?/nAre you happy?"
list = [m.start() for m in re.finditer('/n', my_string)]
You can use enumerate
in a list comprehension to create a list of indices.
>>> [index for index, value in enumerate(my_string) if value == '\n']
[15, 33]
By the way, a new line character is '\n'
not '/n'
(note the slash)