RosettaCodeData/Task/Strip-comments-from-a-string/Python/strip-comments-from-a-strin...

11 lines
273 B
Python

def remove_comments(line, sep):
for s in sep:
i = line.find(s)
if i >= 0:
line = line[:i]
return line.strip()
# test
print remove_comments('apples ; pears # and bananas', ';#')
print remove_comments('apples ; pears # and bananas', '!')