0 votes

I'm trying to check for a palindrome with Python. The code I have is very for-loop intensive.

def isPalindrome(n):

```    lst = [int(n) for n in str(n)]
l=len(lst)
if l==0 || l==1:
return True
elif len(lst)%2==0:
for k in range (l)
#####
else:
while (k<=((l-1)/2)):
if (list[]):
#####

for i in range (999, 100, -1):
for j in range (999,100, -1):
if isPalindrome(i*j):
print(i*j)
break```

I'm missing a lot of code here

PS: The problem is: Find the highest value product of two 3 digit integers that is also a palindrome.

Nov 14, 2018 in Python 87 views

## 1 answer to this question.

0 votes

A pythonic way  and the most simplest way to determine if a given value is a palindrome:

`str(n) == str(n)[::-1]`

Explanation:

• We're checking if the string representation of n equals the inverted string representation of n
• The [::-1] slice takes care of inverting the string
• After that, we compare for equality using ==
answered Nov 14, 2018 by
• 740 points

0 votes
1 answer

## How can I check for NaN in Python?

math.isnan() Checks if the float x is a ...READ MORE

+1 vote
1 answer

## How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

0 votes
1 answer

## What's the canonical way to check for type in Python?

To check if o is an instance ...READ MORE

0 votes
2 answers

## Check a number is Prime or not in Python

There is an efficient way to write ...READ MORE

0 votes
1 answer

## How to check latest change time of each file using glob in python?

You can get the changing time from ...READ MORE

0 votes
1 answer

## how do i change string to a list?

suppose you have a string with a ...READ MORE

0 votes
1 answer

## how can i randomly select items from a list?

if you google it you can find. ...READ MORE

+1 vote
2 answers

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

0 votes
0 answers

## how do i use the enumerate function inside a list?

can you give an example using a ...READ MORE

0 votes
1 answer

## Using Python what kind of applications can be built?

http://en.wikipedia.org/wiki/List_of_Python_software  follow the link and You will see ...READ MORE