1. 字符串分词程序
def split_string(source, splitlist):
output = []
atsplit = True
for char in source:
if char in splitlist:
atsplit =True
else:
if atsplit:
output.append(char)
else:
output[-1] = output[-1] + char
return output
输出结果:
out = split_string("This is a test-of the,string separation-code!"," ,!-")
print out#>>> ['This', 'is', 'a', 'test', 'of', 'the', 'string', 'separation', 'code']