Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,10 @@
|
|||
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', '!')
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import re
|
||||
|
||||
m = re.match(r'^([^#]*)#(.*)$', line)
|
||||
if m: # The line contains a hash / comment
|
||||
line = m.group(1)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
'''Comments stripped with itertools.takewhile'''
|
||||
|
||||
from itertools import takewhile
|
||||
|
||||
|
||||
# stripComments :: [Char] -> String -> String
|
||||
def stripComments(cs):
|
||||
'''The lines of the input text, with any
|
||||
comments (defined as starting with one
|
||||
of the characters in cs) stripped out.
|
||||
'''
|
||||
def go(cs):
|
||||
return lambda s: ''.join(
|
||||
takewhile(lambda c: c not in cs, s)
|
||||
).strip()
|
||||
return lambda txt: '\n'.join(map(
|
||||
go(cs),
|
||||
txt.splitlines()
|
||||
))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(
|
||||
stripComments(';#')(
|
||||
'''apples, pears # and bananas
|
||||
apples, pears ; and bananas
|
||||
'''
|
||||
)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue