I have this initial string.
'bananaappleorangestrawberryapplepear'
And also have a tuple with strings:
('apple', 'plepe', 'leoran', 'lemon')
I want a function so that from the initial string and the tuple with strings I obtain this:
'bananaxxxxxxxxxgestrawberryxxxxxxxar'
I know how to do it imperatively by finding the word in the initial string for every word and then loop character by character in all initial string with replaced words.
But it’s not very efficient and ugly. I suspect there should be some way of doing this more elegantly, in a functional way, with itertools or something. If you know a Python library that can do this efficiently please let me know.
UPDATE: Justin Peel pointed out a case I didn’t describe in my initial question. If a word is ‘aaa’ and ‘aaaaaa’ is in the initial string, the output should look like ‘xxxxxx’.
produces: