Most efficient palindrome program for python -


this question has answer here:

very new programming , trying solve few project euler problems. know python code identifies palindrome , non-palindrome. efficient way this? please show code find efficient problem.

you can checking if string input equal reversed (that's palindrome is).

def check_palindrome(s):     return s == s[::-1] 

[::-1] reverses string because -1 tells how many steps go , negative go through string in reverse.

if need check if integers palindromes, can do:

def check_palindrome(s):     return str(s) == str(s)[::-1] 

Comments

Popular posts from this blog

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -