import re
from typing import List
def fn(s: str, lis: List[str]) -> str:
pattern = "[" + "".join(lis) + "]" + ".*"
lis1 = re.split(pattern, s)
res = ""
for s1 in lis1:
res += s1.rstrip(" ")
return res
def solution(s,l):
# your code here
res = s.split("\n")
for item in l :
for i in range(len(res)):
if item in res[i] :
res[i] = res[i][:res[i].index(item)]
return "\n".join([i.rstrip()for i in res])
assert solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]) == "apples, pears\ngrapes\nbananas"
assert solution("a #b\nc\nd $e f g", ['#', '$']) == "a\nc\nd"
assert solution(" a #b\nc\nd $e f g", ['#', '$']) == " a\nc\nd"
def solution(a:str,b:list)->str:
lines=a.split('\n')
for i in range(len(lines)):
for j in b:
if j in lines[i]:
index=lines[i].index(j)
lines[i]=lines[i][:index].rstrip()
return '\n'.join(lines)
assert solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]) == "apples, pears\ngrapes\nbananas"
assert solution("a #b\nc\nd $e f g", ['#', '$']) == "a\nc\nd"
assert solution(" a #b\nc\nd $e f g", ['#', '$']) == " a\nc\nd"