Strings Checkpoint
A review of this module. Skip it if you feel confident; the next module does not need it.
Fix the mistakes
The slips that cost marks in this module. Spot each one, then check the fix.
Consolidate your string manipulation skills by solving standard placement technical coding round problems.
Alphanumeric palindrome test
Check if a sentence is a palindrome, ignoring spaces, punctuation, and case.
sentence = "A man, a plan, a canal: Panama"cleaned = [ch.lower() for ch in sentence if ch.isalnum()]is_pal = cleaned == cleaned[::-1]print(f"Is palindrome: {is_pal}")Example 1 · Cleaning a customer name
raw = " aRJUN kumar "name = " ".join(raw.split()).title()print(name)print(name[::-1])Arjun Kumar ramuK nujrA
What this code does
split()drops the extra spaces andjoinrebuilds the name with single spaces.title()fixes the capital letters.- The slice
[::-1]shows the name reversed.
Filters characters with ch.isalnum(), converts to lowercase, and checks if reversed matches.
Valid anagram check
Two words are anagrams if they contain the exact same characters with identical frequencies.
word1 = "listen"word2 = "silent"is_anagram = sorted(word1) == sorted(word2)print(f"Are anagrams: {is_anagram}")Example 2 · Building a URL slug
def slugify(title): words = [w.lower() for w in title.split() if w.isalnum()] return "-".join(words)
print(slugify("Python 3 Placement Guide 2026"))python-3-placement-guide-2026
What this code does
- Normalizes headline words to lowercase.
- Joins with hyphens to create URL slug: 'python-3-placement-guide-2026'.
Example 3 · Anagrams need the same case
a = "Listen"b = "Silent"print(sorted(a) == sorted(b))print(sorted(a.lower()) == sorted(b.lower()))False True
What this code does
- A capital
Lsorts differently from a smalll, so the first test is False. - Lower-casing both words first gives the right answer, True.
Sorting both strings yields ['e', 'i', 'l', 'n', 's', 't'] for both words, confirming they are anagrams.
Finish up
Mark complete & continue
Next: Must-do problems: Strings