Tom Tom - 1 year ago 85
Python Question

Python split string with another string in succession

Surpose the string:


split by string:



'ab c d e a b cdea b cdea b cd e abcdeabcde'

How to do this by Python?

Answer Source

This quite matches your expected output, but I don't know what's the logic when 'cdebbe' reaches the end.

s = 'abcdeabcdeabcdeabcdeabcdeabcde'
split = 'cdebbe'

result = []
for c in split:
    left, center, s = s.partition(c)
    if left:

print(' '.join(result)) # ab c d e a b cdea b cd e
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download