I\'m writing a function to replace every n-th letter from a string
def replaceN(str, n): for i in range(len(str)): n=str[i] newStr=str.replace(
Another option, using re:
import re def repl(matchobj): return re.sub('.$','*',matchobj.group(0)) def replaceN(str, n): return re.sub('.'*n,repl,str)
However, this needs additional library. If you have this library already imported, this may be a shorthand method.