def partition(s):
    parents = [[] for _ in range(len(s) + 1)]
    parents[0] = []

    for b, e in iter_palindrome(s):
        parents[e].append(b)

    return [[s[a:b] for (a, b) in seg] for seg in iter_segs(len(s), parents)]
Exemple #2
0
def minCut(s):
    steps = [None for _ in range(len(s) + 1)]
    steps[0] = 0

    for b, e in iter_palindrome(s):
        if steps[e] is None or steps[b] + 1 < steps[e]:
            steps[e] = steps[b] + 1

    return steps[-1] - 1
def minCut(s):
    steps = [None for _ in xrange(len(s)+1)]
    steps[0] = 0

    for b, e in iter_palindrome(s):
        if steps[e] is None or steps[b] + 1 < steps[e]:
            steps[e] = steps[b] + 1

    return steps[-1] - 1
def partition(s):
    parents = [[] for _ in range(len(s)+1)]
    parents[0] = []

    for b, e in iter_palindrome(s):
        parents[e].append(b)

    return [[s[a:b] for (a,b) in seg]
            for seg in iter_segs(len(s), parents)]