all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
24
Task/Strip-block-comments/Python/strip-block-comments-1.py
Normal file
24
Task/Strip-block-comments/Python/strip-block-comments-1.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
def _commentstripper(txt, delim):
|
||||
'Strips first nest of block comments'
|
||||
|
||||
deliml, delimr = delim
|
||||
out = ''
|
||||
if deliml in txt:
|
||||
indx = txt.index(deliml)
|
||||
out += txt[:indx]
|
||||
txt = txt[indx+len(deliml):]
|
||||
txt = _commentstripper(txt, delim)
|
||||
assert delimr in txt, 'Cannot find closing comment delimiter in ' + txt
|
||||
indx = txt.index(delimr)
|
||||
out += txt[(indx+len(delimr)):]
|
||||
else:
|
||||
out = txt
|
||||
return out
|
||||
|
||||
def commentstripper(txt, delim=('/*', '*/')):
|
||||
'Strips nests of block comments'
|
||||
|
||||
deliml, delimr = delim
|
||||
while deliml in txt:
|
||||
txt = _commentstripper(txt, delim)
|
||||
return txt
|
||||
Loading…
Add table
Add a link
Reference in a new issue