Aug-07-2021, 08:16 AM
Iteration of ideas already provided (can't be blamed as efficient but easy to write :-):
from itertools import count paragraph = ( "This example is an example on how to make an example with the" " word example. the example ends here with an example. for example") counter = count(1) while 'example' in paragraph: paragraph = paragraph.replace('example', f"{next(counter)}", 1) print(paragraph)
Output:This 1 is an 2 on how to make an 3 with the word 4. the 5 ends here with an 6. for 7
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.