sample.py
lst = ['1', '2', '3']
delete_for_str = str.maketrans(dict.fromkeys(lst, "<ok>")) #1st argument:Iterator,2nd argument:Character string after replacement
oldstr = '1ho2ge3'
newstr = oldstr.translate(delete_for_str)
print(newstr)
#Output result:
#<ok>ho<ok>ge<ok>
Recommended Posts