I'm looking for help on a function that takes a string, and replaces every character in that string in every way. I'm not quite sure how to word my question so that it makes sense so I'll show you what it's supposed to 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***', '****']
Did that all out by hand, but even if I made a mistake, you should get the idea of what I'm looking for now. The final case (all *'s) isn't required but I put it in there to make sure the problem was understood.
Here is what I've come up with so far but it doesn't quite 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. Would like this answered in Python if possible, but if you don't know Python, then pseudocode or another language would be acceptable. If it's written clearly, I'm sure I could convert it into Python on my own.