Finding out next palindrome of numbers in a given list?

 The following program will find out the palindrome of numbers in a given list. If the number in the list is less than or equal to 10, it will be printed as such; if the number in the list is greater than 10, the next palindrome of that number will be calculated. But if the number greater than 10 is already a palindrome, then 1 will be added to it and then the next palindrome of that number will be found.

    

   mylist = [1, 6, 10, 11, 88, 535, 5439]

plist = []

for number in mylist:
    if number <= 10:
        plist.append(number)
    elif number > 10:
        # comment out the following if block if palindrome in list to be written as such
        if str(number) == str(number)[::-1]:
            number += 1
        while str(number) != str(number)[::-1]:
            number += 1            
        plist.append(number)
    
print(plist)

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes