![]() |
School projet - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: School projet (/thread-17361.html) |
School projet - robalexx - Apr-08-2019 Hello :) I have a project to do and it is almost done (i think), I just have some error. Let me explain : I have 2 files. In the first file, there is something like a lexicon (with word and grammatical class) and in the second one a story (with word and grammatical class too). With these files, I have to find in the second file all the names, find a match in the lexicon and replace it by the seventh names after. It is call the S+7 method. For now, I have 2 lists. The first one contain all the name in the lexicon and the second have all the words in the story. For the processing I wrote this : i = 0 j = 0 while i < len(Listmots)-1: if Listmots[i] in ListLexique: j = ListLexique.index(Listmots[i]) Listmots[i] = ListLexique[j+7] print(Listmots[i], end=" ", file=histoireResultat) i = i + 1 print(Listmots[i], end=" ", file=histoireResultat)Like I said before, it is almost done. The only problem is that in the output file, I have the "old" name AND the "new" name. I don't know how to deal with it. Can someone help me please ? :) Thanks :) PS : sorry for my bad english :p the variables are in french, to help you this is some informations : - Listmot[] == list of all word in the story - Listlexique[] == list of all name in the lexicon - histoireResultat == output file RE: School projet - heiner55 - May-03-2019 txt = "I like bananas" x = txt.replace("bananas", "apples") print(x) |