Answer to Question #75358 in Python for Andrew Forrester

Question #75358
1. Write a function hideShow that accepts two string arguments, an input string and a masking string. The masking string is a string consisting of ‘0’s and ‘1’s that has the same length as the input string. The function then returns a new string that is the same as the input string, except that it is masked. That is, in any position where the masking string contains a ‘0’ the input character is replaced by a ‘#’, whereas if the masking string contains a ‘1’, the character is unchanged. See the following sample output:
>>> hideShow( 'apple', '11001')
'ap##e'
>>> hideShow('apple','00000')
'#####'
>>> hideShow('apple','11111')
'apple'
>>> hideShow('abcdefghijklmnopqrstuvwxyz',13*'01')
'#b#d#f#h#j#l#n#p#r#t#v#x#z'
>>> hideShow( 'df###re##', '101010101' )
'd#####e##'
>>>
1
Expert's answer
2018-04-03T10:53:05-0400
def hideShow(input_string, masking_string):
res = []
for k, v in enumerate(input_string):
if masking_string[k] == "0":
res.append("#")
else:
res.append(v)

return "".join(res)


print(hideShow( 'apple', '11001'))
print(hideShow('apple','00000'))
print(hideShow('apple','11111'))
print(hideShow('abcdefghijklmnopqrstuvwxyz',13*'01'))
print(hideShow( 'df###re##', '101010101' ))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS