<jupyter_start><jupyter_text>Extreme PalindromesGiven a string, split it into as few strings as possible such that each string is a palindrome. For example, given the input string racecarannakayak, return ["racecar", "anna", "kayak"]. Given the input string abc, return ["a", "b", "c"].<jupyter_code>def is_palindromes(s): 
    return s == s[::-1] # slick way to get a reversal

def split_into_palindromes(s): 
    if not s: 
        return [] 
    if is_palindrome(s): 
        return [s] 
    
    min_cut = None
    for i in range(1, len(s)): 
        curr_cut = split_into_palindromes(s[:i]) + split_into_palindromes(s[i:])
        if min_cut is None or len(curr_cut) < len(min_cut): 
            min_cut = curr_cut
    return min_cut
test_ = "racecarZ"
test_[::-1]<jupyter_output><empty_output><jupyter_text>Remember...  a[start:stop:step]  start through not past stop, by step:stop value represents the first value that is not in the selected slice.  To skip specifying a given argument, you can use None. `a[::-1]` is equivalent to `a[None:None:-1]`so you're not specifying a given argument. So what that amounts to is all items in the area, step through from the reverse.<jupyter_code>test_[::-1]
test_[None:None:-1]
def is_palindrome(s): 
    return s == s[::-1] 

def split_into_palindromes(s): 
    
    # Remember comprehensions... 
    # new_list = [expression for i in old_list if filter(i) ] 
    # expression for item in list if condition] 
    
    # this just initializes a list of Nones. 
    # Then, this list of Nones is used in another list comprehension to make a matrix
    A = [[None for _ in range(len(s))] for _ in range(len(s))] 
    
    # set all substrings of length 1 to be true..
    for i in range(len(s)): 
        A[i][i] = True
        
    # try all substrings of length 2
    for i in range(len(s) - 1): 
        A[i][i+1] = s[i] == s[i+1] # returns True / False
    
    i, k  = 0 , 3
    while k <= len(s): 
        while i < (len(s) - k + 1): 
            j = i + k - 1
            A[i][j] = A[i+1][j-1] and s[i] == s[j] 
            i += 1
        k+= 1
        i = 0 
        
    P = [None for _ in range(len(s) + 1)] 
    P[0] = [] 
    for i in range(len(P)): 
        for j in range(i): 
            matrix_i = i - 1
            
            if A[j][matrix_i]: 
                if P[i] is None or (len(P[j]) + 1 < len(P[i])): 
                    P[i] = P[j] + [s[j:i]]
    
    return P[-1] 
    
    
[None for _ in range(5)]
[[None for i in range(5)] for j in range(10)]
# if you don't use indices, it looks cleaner
[[None for _ in range(5)] for _ in range(10)]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12831188493565482, 'fraction_numerical': 0.012869038607115822, 'mean_word_length': 2.3583227445997457, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '251095', 'license': 'MIT', 'n_tokens_mistral': 980, 'n_tokens_neox': 916, 'n_words': 315, 'path': 'Daily/Extreme Palindromes.ipynb', 'repo_name': 'jasonyum/python_go', 'size': '2642'}