typestar

Palindrome check in Python

A string-cleaning warm-up built on slicing.

def is_palindrome(text):
    cleaned = "".join(ch.lower() for ch in text if ch.isalnum())
    return cleaned == cleaned[::-1]

How it works

  1. Keeps only letters and digits, lowercased.
  2. [::-1] reverses the cleaned text for comparison.
  3. Equal means it reads the same both ways.

Keywords and builtins used here

The run, in numbers

Lines
3
Characters to type
117
Tokens
39
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 26 seconds.

Type this snippet

Step 6 of 9 in Strings, step 12 of 72 in Language basics.

← Previous Next →