0
0
DSA Pythonprogramming~10 mins

Palindrome Detection in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a string is the same forwards and backwards.

DSA Python
def is_palindrome(s):
    return s == s[1]
Drag options to blanks, or click blank then click option'
A[::-1]
B[1:]
C[:1]
D[::-2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using [1:] or [:1] which do not reverse the string.
2fill in blank
medium

Complete the code to ignore case when checking palindrome.

DSA Python
def is_palindrome(s):
    s = s.lower()
    return s == s[1]
Drag options to blanks, or click blank then click option'
A[1:]
B[::-1]
C[:1]
D[::2]
Attempts:
3 left
💡 Hint
Common Mistakes
Not reversing the string correctly after lowering case.
3fill in blank
hard

Fix the error in the code to correctly check palindrome ignoring spaces.

DSA Python
def is_palindrome(s):
    s = s.replace(' ', '')
    return s == s[1]
Drag options to blanks, or click blank then click option'
A[::-1]
B[1:]
C[:1]
D[::2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect slicing that does not reverse the string.
4fill in blank
hard

Fill both blanks to create a palindrome check ignoring case and non-alphanumeric characters.

DSA Python
import re

def is_palindrome(s):
    s = re.sub([1], '', s).lower()
    return s == s[2]
Drag options to blanks, or click blank then click option'
A'[^a-zA-Z0-9]'
B' '
C[::-1]
D[1:]
Attempts:
3 left
💡 Hint
Common Mistakes
Removing only spaces instead of all non-alphanumeric characters.
Using wrong slice to reverse.
5fill in blank
hard

Fill all three blanks to create a palindrome check ignoring case, spaces, and punctuation.

DSA Python
import string

def is_palindrome(s):
    s = ''.join(c for c in s.lower() if c not in [1])
    return s == s[2] and len(s) > [3]
Drag options to blanks, or click blank then click option'
Astring.punctuation + ' '
B[::-1]
C0
Dstring.whitespace
Attempts:
3 left
💡 Hint
Common Mistakes
Not removing all punctuation and spaces.
Using wrong slice to reverse.
Not checking string length.