I want to remove from my list every \n that is before the element 'Ecrire'. It work just for the first case and not the other cases, And I really don't understand why Here is my code :
Corps2 = ['Debut', '\n', '\n', 'Note', ' ', '<-', ' ', 'Saisie()', ' ', '', '\n', '\n', 'Selon que\n', ' ', 'Note', ' ', '≥', ' ', '16', ' ', '', ' ', '', ' ', ':', ' ', '', '\n', '\n', 'Ecrire', ' ', "('TB')", '\n', '\n', '', ' ', 'Note', ' ', '≥', ' ', '14', ' ', '', ' ', '', ' ', ':', ' ', '', '\n', '\n', 'Ecrire', ' ', "('B')", '\n', '\n', '', ' ', 'Note', ' ', '≥', ' ', '12', ' ', '', ' ', '', ' ', ':', ' ', '', '\n', '\n', 'Ecrire', ' ', "('AB')", '\n', '\n', '', ' ', 'Note', ' ', '≥', ' ', '10', ' ', '', ' ', '', ' ', ':', ' ', '', '\n', '\n', 'Ecrire', ' ', "('Passable')", '\n', '\n', 'Sinon', ' ', ':', ' ', 'Ecrire', ' ', "('Redoublant')", '\n', '\n', 'Fin_Si']
for i in Corps2:
if i =='Ecrire' and Corps2[Corps2.index('Ecrire')-2 :Corps2.index('Ecrire')]==['\n','\n'] :
del Corps2[Corps2.index('Ecrire')-2 :Corps2.index('Ecrire')]
Aucun commentaire:
Enregistrer un commentaire