So, I have this code snippet where I read a text from a TXT-file:
file = open('test.txt', 'r')
content = file.readlines()
file.close()
print(content)
The printout:
['My name is x.\n', 'I am 45 years old.\n', '\n', 'My girlfriends name is y.\n', 'She is way too old for me.\n', 'y wears weird clothes.\n', '\n', 'Good bye.']
So the content if this TXT-file would be:
My name is x.
I am 45 years old.
My girlfriends name is y.
She is way too old for me.
y wears weird clothes.
Good bye.
What I want to is splitting the list content into three lists, by looping through it, breaking when reaching '\n' and putting each line not separated by a new line in a list. Something like:
['My name is x.\n', 'I am 45 years old.\n']
['My girlfriends name is y.\n', 'She is way too old for me.\n', 'y wears weird clothes.\n']
['Good bye.']
The reason I wan't to do this is because i wan't "My name is x" to have index one, "I am 45 years old." to have index two, "My girlfriends name is y" to have index one, and so on. Maybe there's a better way to solve this problem than to splitting the list containing all the sentences in three? I tried something like:
a, b, c = 0, 0, 0
for i in content:
if i != '\n':
a += 1
b += 1
elif i != '\n':
b += 1
c += 1
else:
c += 1
break
However, you quickly realise my coding-skills aren't the best. :P