Change language

All palindrome numbers in the list

|

Examples :

  Input:  10 121 133 155 141 252  Output:  121 141 252 Total palindrome nos. are 3  Input:  111 220 784 565 498 787 363  Output:  111 565 787 363 Total palindrome nos. are 4 

1. Access an item from the list. 
2. Now we get its inverse value in the temporary variable. 
3. Now compare the value of the list item by its inverse value, if they both match, output the list item and increment the counter c by 1.
4. Continue this procedure until the list is empty. 
5. Now print the counter value, that is, the total number of palindrome numbers in the given list.

# Python program for counting and
# print all numbers of palindromes in the list.

 

def palindromeNumbers (list_a): 

 

  c = 0

 

# loop until list is empty

  for i in list_a: 

 

# Find the reverse of the current license plate

t = i

rev = 0

while t"  0 :

rev = rev * 10 + t % 10

t = t / 10

 

# compare the turnover with the current number

if rev = = i:

print i,

  c = c + 1

  

  print

print "Total palindrome nos. are " , c

  print

 
# Driver code

def main ():

 

list_a = [ 10 , 121 , 133 , 155 , 141 , 252 ]

palindromeNumbers (list_a)

 

  list_b = [ 111 , 220 , 784 , 565 , 498 , 787 , 363 ]

palindromeNumbers (list_b) 

 

if __ name__ = = " __ main__ " :

  main ()  # call the main functions

Exit:

 121 141 252 Total palindrome nos. are 3 111 565 787 363 Total palindrome nos. are 4 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically