Finding Palindromes Using Python
ECX 30 Days of Code
Day 3
Palindromic Numbers
Task
A palindromic number is a number that remains the same when its digits are reversed. Write a function that prints out all palindromic numbers less than a given input, and returns the total number of ...
thecodingprocess.hashnode.dev2 min read
Nice. Here is another approach using functions from
itertools. I really like the functions in itertools for these kinds of problemsfrom itertools import count, takewhile def is_palindromic(num): return num == int(str(num)[::-1]) def palindromic(max_num): all_numbers = count() nums_palindrome = (num for num in all_numbers if is_palindromic(num)) return takewhile(lambda x: x < max_num, nums_palindrome) output = list(palindromic(500)) print(output) print(len(output))