Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

check palindrome in python using recursion

def isPalindrome(string):
  	#termination condition: the string is one character or less
    if (len(string) <= 1):
        return True
    if (string[0] == string[-1]):
        return isPalindrome(string[1:-1])
    else:
        return False
Comment

Palindrome Check using for loop in python

p = list(input())
for i in range(len(p)):
    if p[i] == p[len(p)-1-i]:
        continue
    else:
         print("NOT PALINDROME")
         break
else:
    print("PALINDROME")
Comment

How to check for palindromes in python

def is_palindrome(s):
  reverse = s[::-1]
  if (s == reverse):
    return True
  return False

s1 = 'racecar'
s2 = 'hippopotamus'

print(''racecar' a palindrome -> {}'.format(is_palindrome(s1)))
print(''hippopotamus' a palindrome -> {}'.format(is_palindrome(s2)))


# output

# 'racecar' is a palindrome -> True
# 'hippopotamus' is a palindrome -> False
Comment

Python - How To Check if a String Is a Palindrome

word = input() if str(word) == str(word)[::-1] :     print("Palindrome") else:     print("Not Palindrome")
Comment

How to check if a given string is a palindrome, in Python?

"""
This implementation checks whether a given
string is a palindrome. A string is 
considered to be a palindrome if it reads the
same forward and backward. For example, "kayak"
is a palindrome, while, "door" is not. 

Let n be the length of the string

Time complexity: O(n), 
Space complexity: O(1)
"""
def isPalindrome(string):
    # Maintain left and right pointers
    leftIdx = 0
    rightIdx = len(string)-1
    while leftIdx < rightIdx:
        # If chars on either end don't match
        # string cannot be a palindrome
        if string[leftIdx] != string[rightIdx]:
            return False
        # Otherwise, proceed to next chars
        leftIdx += 1
        rightIdx -= 1
    return True

print(isPalindrome("kayak"))  # True
print(isPalindrome("door"))  # False
Comment

how to check a string is palindrome or not in python

s = "001100"

if s == s[::-1]:
    print(s, "is a Palindrome string.")
else:
    print("Not a palindrome string.")

    
Comment

How to check palindrom in python

myString = "aba"
if myString == myString[::-1]:
	print("The string '" + myString + "' is a palindrome")
else:
	print("The string '" + myString + "' is not a palindrome")
Comment

check palindrome in python

string = input("Type a string: ")
if string[::-1] == string: 
	print(string,"This string is Palindrome")
else:
	print(string,"This string is not Palindrome")
Comment

finding palindrome in python

is_palindrome = lambda phrase: phrase == phrase[::-1]

print(is_palindrome('anna')) # True 
print(is_palindrome('rats live on no evil star')) # True 
print(is_palindrome('kdljfasjf')) # False 
Comment

palindrome of a number in python using recursion

def reverse(n, rev=0):
    if n == 0:
        return rev 
    rev = rev * 10 + (n % 10)
    rev = reverse(n // 10, rev)
    return rev
n = int(input("Enter a no.:"))
if n == reverse(n):
    print(n,' is a Palindrome')
else:
    print(n,' is not a Palindrome')
Comment

PREVIOUS NEXT
Code Example
Python :: visualize 3 columns of pandas 
Python :: NumPy bitwise_or Syntax 
Python :: NumPy invert Code When the input is a number 
Python :: NumPy packbits Code Packed array along default axis 
Python :: All possible combinations of multiple columns 
Python :: django view - apiview decorator (retrieve, update or delete - GET, PUT, DELETE) 
Python :: save axis and insert later 
Python :: python override inherited method 
Python :: cast set 
Python :: Python PEP (class) 
Python :: Use PIP from inside script 
Python :: get token eth balance python 
Python :: knn compute_distances_one_loop 
Python :: download Twitter Images with BeautifulSoup 
Python :: find smallest element not present in list python 
Python :: Examples of incorrect code for this rule: 
Python :: python output 
Python :: Python batch file rename 
Python :: app.callback output is not defined 
Python :: how to blend pixels in pygame 
Python :: python go back one using abspath 
Python :: ring Create Lists 
Python :: qtextedit insert unicode 
Python :: create schema for table for django 
Python :: cuantas palabras hay en una frase en python 
Python :: Convert matlab to Python Reddit 
Python :: Can Selenium python Web driver helps to extract data from DB 
Python :: ConversionofDatatypes-I 
Python :: defaultdict python inport 
Python :: java to python code conversion 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =