I am looking for help for a function that takes a string, and in every way replaces every character in that string. I'm not quite sure how to formulate my question so that it makes sense, so I will show you what it should do.
stars('1') returns ['*'] stars('12') returns ['*1', '1*', '**'] stars('123') returns ['*23', '1*3', '12*', '**3', '*2*', '**1', '***'] stars('1234') returns ['*234', '1*34', '12*4', '123*', '**34', '*2*4', '*23*', '1**4', '1*3*', '12**', '***4', '**3*', '*2**', '1***', '****']
I did it all manually, but even if I made a mistake, you should get an idea of ββwhat I'm looking for now. The final case (all *) is not required, but I put it there to make sure the problem is understood.
Here is what I came up with so far, but it does not work.
def stars(n): lst = [] length = len(n) for j in xrange(0, length): p = list(n) for k in xrange(j, length): p[k] = '*' lst += [''.join(p)] return lst
Output:
'1' returns ['*'] '12' returns ['*2', '**', '1*'] '123' returns ['*23', '**3', '***', '1*3', '1**', '12*'] '1234' returns ['*234', '**34', '***4', '****', '1*34', '1**4', '1***', '12*4', '12**', '123*']
Any help would be greatly appreciated. If possible, respond to Python, but if you don't know Python, then pseudo-code or another language would be acceptable. If it's written clearly, I'm sure I can convert it to Python myself.