Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
School projet
#1
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
Reply
#2
txt = "I like bananas"
x = txt.replace("bananas", "apples")
print(x)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Smile Final Projet - Credit Risk Rauchvant 3 2,429 Nov-18-2020, 03:21 PM
Last Post: Rauchvant

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020