computer science 101 unit4--exercise

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']




                                   

                

                        

猜你喜欢

转载自blog.csdn.net/qq_31805127/article/details/79555134