Im having a hard time returning my list without the
'\n'
. Here's the code :
evenement = open("evenements.txt", "r", encoding="utf-8-sig")
liste = []
chaine = ""
for line in evenement:
chaine += line
chaine_split = chaine.split('/')
for element in chaine_split:
liste.append(element.strip('\n'))
print(liste)
I had to split the strings in my list so this is why im using
chaine.split('/')
before removing the backslash. I know it can be tricky to manipulate split and strip on lists so this is why im having a hard time. Code is returning :
['Musique', 'Shawn Phillips', '2018-08-24', '2018-08-24\nMusique', "L'avenue Royale fête l'été!", '2018-08-25', '2018-08-25\nMusique', 'Perséides musicales', '2018-08-03', '2018-08-03\n....
but has to return :
[['Musique', 'Shawn Phillips', '2018-08-24', '2018-08-24]
[Musique', "L'avenue Royale fête l'été!", '2018-08-25', '2018-08-25]
[Musique', 'Perséides musicales', '2018-08-03', '2018-08-03]]
As you can see i also have to stock all my lists in a global list so it would be nice if you could help me with that too, but im mostly focusing on getting rid of the \n while keeping in mind that i have to keep the .split for the
'/'
.
What I have tried:
Had a lot of error messages returned because i realised i couldnt manipulate a list like a string so this is why i decided to use a for loop to manipulate each element of my list.