python - Generating pass_words with input mask -


i have such input masked word --- , want replace - numbers(0-9)

code:

def masker(input_mask,pattern):  s = list()  s = (itertools.product(pattern,repeat=1))   in input_mask:   if ( i=='-'):     j in s :     print (input_mask.replace('-',''.join(j)))   masker ('-a-' , '123') 

but output is:

1a1 2a2 3a3 1a1 2a2 3a3 

and main goal output:

1a1 1a2 1a3 2a1 .... .... 3a3 

in code j = '1' in first run. replace - that...


my suggestion use str.format mask (i.e. replacing - {}). this:

from itertools import product  def masker(input_mask, pattern):     mask = input_mask.replace('-', '{}')  # mask = '{}a{}'     values in product(pattern, repeat=2):         print(mask.format(*values))  masker(input_mask='-a-', pattern='123') 

also note repeat=2 in product. make more generic need use repeat=input_mask.count('-').


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -