Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out. Example: Given an input string of:
apples, pears # and bananas
grapes
bananas !apples
The output expected would be:
apples, pears
grapes
bananas
My Function:
import regex
def solution(string,markers):
i = regex.sub('{}.*|\s*{}.*'.format(*markers),'',string)
return i
1) solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"])
Ideal Result: "apples, pears\ngrapes\nbananas"
Actual Result: 'apples, pears \ngrapes\nbananas' Error: There's a space after 'pears'
2) solution("a #b\nc\nd $e f g", ["#", "$"])
Ideal Result: "'a\nc\nd"
Actual Result: 'a \nc\nd $e f g' Error: There's a space after 'a' and '(space)$e f g' shouldn't be there