Diego Gaglione
Diego Gaglione

Reputation: 1

Replacing words in string with cycle for

import re
frase = "I read some text writed here"
ea = ["ReplaceA", "ReplaceB", "ReplaceC"]
eax = ["some", "writed", "here"]
for e in ea:
            print(e)
            count = ea.count(e)
            print(count)
            ready_message = frase.replace(eax[count], for e in ax)  
print(ready_message)

Result: ReplaceA 1 ReplaceB 1 ReplaceC 1 I read some text ReplaceB here

I want that ready_message is:

I read ReplaceA text ReplaceB ReplaceC

and not:

I read some text ReplaceB here

Upvotes: 0

Views: 63

Answers (1)

user15801675
user15801675

Reputation:

Try using .zip

frase = "I read some text writed here"
ea = ["ReplaceA", "ReplaceB", "ReplaceC"]
eax = ["some", "writed", "here"]
for i,j in zip(ea,eax):
    frase=frase.replace(j,i)
print(frase)

Upvotes: 1

Related Questions