I am trying to get output like below using pythone code...any suggestions?
list=["ABCPMCABCCMD","CMDABC"] list2=["ABC","CMD"]
output: [ABCABCCMD,CMDABC]
You can use re
module:
import re
list1 = ["ABCPMCABCCMD", "CMDABC", "ABCMD"]
list2 = ["ABC", "CMD"]
r = re.compile("|".join(re.escape(w) for w in list2))
out = ["".join(r.findall(word)) for word in list1]
print(out)
Prints:
['ABCABCCMD', 'CMDABC', 'ABC']