import re
def strip_comments(words,markers:list):
for i in markers:
if words.find(i)!=-1:
li1=re.findall('\\'+i+'.*',words)
for j in li1:
words=words.replace(j,'')
else:
continue
return words
def strip_comments(words,markers):
line = words.split('\n')
temp_list=[]
for i in markers:
for j in line:
temp_list.append(j.split(i)[0].rstrip())
line=temp_list
result_list = temp_list
temp_list=[]
return '\n'.join(result_list)
def strip_comments(words: str, markers: list) -> str:
result = []
words_list = words.split('\n')
for words in words_list:
for m in markers:
words = words.split(m)[0]
result.append(words.rstrip())
return '\n'.join(result)
assert strip_comments("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]) == "apples, pears\ngrapes\nbananas"
assert strip_comments("a #b\nc\nd $e f g", ["#", "$"]) == "a\nc\nd"
for item in wordsL:
for marker in markers:
item = item[:item.find(marker)].rstrip() if item.find(marker) >0 else item
wordF.append(item)
return '\n'.join(wordF)
def strip_comments(words: str, markers: list) -> str:
words_list = words.split('\n')
for marker in markers:
for word in words_list:
if marker in word:
words_list[words_list.index(word)] = word.split(marker)[0]
return '\n'.join([word.rstrip() for word in words_list])
assert strip_comments("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]) == "apples, pears\ngrapes\nbananas"
assert strip_comments("a #b\nc\nd $e f g", ["#", "$"]) == "a\nc\nd"