I am trying to put my file.txt
into a list and then each index into different lists while all the lists remain in the initial list. I have been able to add it into a single list so far.
Here's my code:
with open("evenements.txt", "r", encoding="utf-8-sig") as evenement:
liste_evenement = evenement.readlines()
print(liste_evenement)
I want my code to return :
[['index_1'],['index_2'], ...]
Do I have to use a for
loop? or even a while
? I'm a little confused because of the \n
at the end of every line of my evenements.txt
, so if you could help me with that because I am familiar with .strip()
when I use it on a string but its not working on a list.
EDIT : here's a sample of what i need to do now :
My code is now returning :
[['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'], 'Musique/Gaétan Leclerc chante Félix et…/2018-08-17/2018-08-17']]
What i need to do now is that i need to add a " for every '/' in my code so a " between Musique and shawn and another one between phillips and 2018, except between the Year/Month/Day (just look at the result down below. Keep in mind that this is just a part of the code and my list actually contains 160 index.
so heres the result that im looking for :
[['Danse', 'Samedi de danser...', 202, 202],