class Solution:
    def partition(self , s ):
        # write code here
        res = []
        def dfs(i, tmp):
            if i == len(s):
                res.append(tmp[:]) 
                return
            for j in range(i+1, len(s)+1):
                t = s[i:j]
                if t == t[::-1]:
                    tmp.append(t[:])
                    dfs(j, tmp)
                    tmp.pop()
        dfs(0, [])
        return res

回溯递归分割回文串