uaveiro-leci/1ano/1semestre/fp/extra3/ex03.py

16 lines
380 B
Python
Raw Normal View History

# Given a string s and a string t, return a string in which all the characters
# of s that occur in t have been replaced by a _ sign. The comparisons are
# case sensitive.
def replaceCharactersWithUnderscores(s, t):
# Your code here...
new_str = ""
for c in s:
if c in t:
new_str += '_'
else:
new_str += c
return new_str