human
I am working on the file "Manage Complexity.ipynb".
The first task is:
Subpalindrome
Can you write Python program for it?

=====
Give me a the Python program you requested?
assistant
#Here is the Python program you requested.

def isPalindrome(text):
    text = text.lower()
    L = len(text)
    if L % 2 == 0:
        return text[:L/2] == text[-1:-1+L/2:-1]
    else:
        return text[:L/2] == text[-1:L/2:-1]
    
def longest_subpalindrome_slice(text):
    "Return (i, j) such that text[i:j] is the longest palindrome in text."
    if text == "":
        return (0, 0)
    else:
        L = len(text)
        ans, Len = (0, 1), 1
        for i in xrange(L):
            j = i + Len
            while j <= L:
                if isPalindrome(text[i:j]) and j - i > Len:
                    ans = (i, j)
                    Len = j - i
                j += 1
        return ans

def test():
    L = longest_subpalindrome_slice
    assert L('racecar') == (0, 7)
    assert L('Racecar') == (0, 7)
    assert L('RacecarX') == (0, 7)
    assert L('Race carr') == (7, 9)
    assert L('') == (0, 0)
    assert L('something rac e car going') == (8,21)
    assert L('xxxxx') == (0, 5)
    assert L('Mad am I ma dam.') == (0, 15)
    return 'tests pass'

import cProfile
cProfile.run("test()")

def longest_subpalindrome_slice(text):
    "Return (i, j) such that text[i:j] is the longest palindrome in text."
    if text == "": return (0, 0)
    def length(slice):
        a, b = slice
        return b-a
    candidates = [grow(text, start, end)
                 for start in range(len(text))
                 for end in (start, start+1)]
    return max(candidates, key=length)

def grow(text, start, end):
    "Start with a 0- or 1- length palindrome; try to grow a bigger one."
    L = len(text)
    while (start > 0 and end < L
           and text[start-1].upper() == text[end].upper()):
        start -= 1
        end += 1
    return (start, end)

cProfile.run("test()")