I have this starting line.
'bananaappleorangestrawberryapplepear'
And also have a tuple with the lines:
('apple', 'plepe', 'leoran', 'lemon')
I need a function, so from the source string and the tuple with the strings, I get the following:
'bananaxxxxxxxxxgestrawberryxxxxxxxar'
I know how to really do this by finding a word in the source line for each word, and then encode character by character in the entire source line with the replaced words.
But it is not very efficient and ugly. I suspect there must be some way to do this more elegantly, functionally, using itertools or something else. If you know a Python library that can do this efficiently, let me know.
UPDATE : Justin Peel pointed to a case that I did not describe in my original question. If the words "aaa" and "aaaaaa" are on the start line, the result should look like "xxxxxx".
source
share