Python: Finding palindromes in a list
<pre><code>def num_sequence (num1, num2):
#This function takes the lower and upper bound and builds a list.
    array = []
    for i in range(num2 + 1):
        if i &gt;= num1:
            array.append(i)
    return array

def inverted_sequence (array):
#This function takes the previous and list inverts the numbers in every element.
    for i in range(len(array)):
        if array[i] &gt; 10:
            array[i] = str(array[i])
            #Converts the i element of the array to a string.
            array[i] = array[i][::-1]
            #Inverts the the position of the numbers in every element.
            array[i] = int(array[i])
            #Converts the i element of the array to an integer.
    return array


def main ():
    #Main program.

    lower = int(input("Type the lower bound:    "))
    upper = int(input("Type the upper bound:    "))

    sequence = num_sequence(lower, upper)
    inv_sequence = sequence[:]
    inv_sequence = inverted_sequence(inv_sequence)

    print (sequence)
    print (inv_sequence)
    """While loop inside the for loop that checks if the number is a palindrome.
    if to check if it is a palindrome return True, else return False"""
    pal_count = 0
    seq_sum = []
    for i in range(len(sequence)):
        if sequence[i] != inv_sequence[i]:
            while sequence[i] != inv_sequence[i]:
                seq_sum.append(sequence[i] + inv_sequence[i])
                sequence = seq_sum
                inv_sequence = inverted_sequence(inv_sequence)
                print (seq_sum)
        if sequence[i] == inv_sequence[i]:
            pal_count *= 1
    print (pal_count)


main()
</code></pre>

<p>I am trying to make a program that finds all the palindromes in a range of numbers and if they are not palindromes, reverse the number and add it to the original until it becomes a palindrome. In my code I created a list of numbers with two inputs and name the list sequence. inv_sequence is the previous list but with numbers of each element reversed. when i try to add sequence[i] and inv_sequence[i] the program throws an error saying that the list is out of range. I am testing the program with the lower bound being 5 and the upper bound being 15.</p>

<p>I assume that you mean that you want the final list to contain the lowest palindrome in the sequence formed by the sum of the previous number in the sequence and the result of reversing the previous number in the sequence.</p>

<p>If so, here is some code (not bulletproof):</p>

<pre><code>#checks if a number is a palindrome by comparing the string written fowards
#with the string written backwards
def is_pal(x):
    if str(x)==str(x)[::-1]:
        return True
    return False

#iterates a number by adding and reversing until it is a palindrom
def iter_pal(x):
    while not is_pal(x):
        x+=int(str(x)[::-1]) #adds the number's reverse to itself
    return x        

#main program
def main():
    #gets input
    lower = int(input("Type the lower bound:    "))
    upper = int(input("Type the upper bound:    "))

    #uses range to make the sequence of numbers
    sequence = list(range(lower,upper+1))

    #iterates through the list performing iter_pal
    for i in range(upper-lower+1):
        sequence[i]=iter_pal(sequence[i])

    #prints the final sequence
    print(sequence)

main()
</code></pre>

<p>I'm not sure what you will do with the <a href="https://en.wikipedia.org/wiki/Lychrel_number" rel="nofollow">Lychrel numbers</a>.</p>

python python-3.x