Reverse a string
Return the characters of the string in reverse order.
Palindrome check
Return True if the string reads the same forwards and backwards (ignoring case and non-alphanumeric).
Count vowels
Count the number of vowels (a, e, i, o, u) in a string (case-insensitive).
Title case converter
Return the string with each word capitalised.
Anagram check
Return True if two strings are anagrams of each other.
Strip and Collapse Whitespace
Write a function that strips leading/trailing whitespace and collapses inner runs of whitespace to single spaces.
Snake case to camel case
Implement a function that converts snake_case strings to camelCase.
Camel case to snake case
Write a function that converts camelCase input to snake_case while handling acronyms and numbers correctly.
Remove punctuation
Write a function that removes all ASCII punctuation characters from a string.
Is pangram
Write a function that determines whether a given string is a pangram, ignoring case and non-letter characters.
Caesar Cipher Shift
Implement a function to apply a Caesar cipher shift to a string, preserving case and ignoring non-letters.
Repeat each character n times
Given a string s and an integer n, return a new string where each character of s is repeated n times consecutively.
Longest word in a sentence
Write a function that returns the longest word from a sentence, with first-occurrence tie-breaking.
Replace vowels with stars
Write a function that replaces every vowel in a given string with an asterisk.
Is isogram
Implement a function that determines whether a string is an isogram (no repeated letters, case-insensitive).
Extract Digits Only
Given a string that may contain letters, symbols, and whitespace, extract all digits in order and return them as an integer.
Kebab Case a Phrase
Implement a function that converts a phrase into lowercase kebab-case, handling spaces, punctuation, and camelCase.
Normalize quotes
Replace all typographic quote characters with straight ASCII quotes.
Remove Consecutive Duplicate Letters
Implement a function that removes consecutive duplicate letters from a string, keeping only one occurrence of each run.
Interleave Two Strings
Given two strings s1 and s2, return a new string that interleaves them character by character, starting with s1.
Is rotation of another string
Write a function to determine if one string is a rotation of another string.
Initials from a Full Name
Return the uppercase initials of each word in a given full name.
Count words in a sentence
Implement a function to count words in a sentence, ignoring extra whitespace and handling empty strings.
Center a string in a width
Write a function that centers a string within a specified width by adding spaces on both sides.
Reverse Words in a Sentence
Reverse the order of words in a sentence while preserving single spaces between words.
Count consonants
Write a function that counts the number of consonant letters in a string.
Is pangram?
Implement is_pangram(s) to return True if the string contains every letter from 'a' to 'z' at least once, ignoring case and non-alphabetic characters.
Remove Duplicates from String
Given a string, return a new string with each character that repeats consecutively reduced to a single occurrence.
Longest Word Finder
Write a function that extracts alphabetic words from a string and returns the longest one, with ties broken by earliest position.
Abbreviate Name
Create a function that takes a full name and returns an abbreviated version with initials and the last name.
Mask email address
Given an email address, return a masked version that hides everything but the first and last character of the local part and the domain.
Extract digits from string
Write a function that extracts all digit characters from a given string, preserving their original order.
Replace Spaces with Dashes
Write a function that replaces every space in a string with a dash.
Snake case converter
Implement a function that converts a string to snake_case according to given rules.
Camel Case Converter
Write a function that converts a space-separated phrase into lower camelCase.
Kebab Case Converter
Implement a function that converts any string to kebab-case, handling spaces, underscores, camelCase, and punctuation.
Count Syllables (Simple)
Count syllables in a word by counting groups of consecutive vowels (a, e, i, o, u).
Is isogram?
Write a function that checks whether a given word is an isogram, ignoring letter case and only considering alphabetic characters.
Rotate String Right
Implement a function that rotates a given string to the right by a specified number of positions, handling shifts larger than the string length.
Expand compressed string
Implement a function that expands run-length encoded strings (e.g., 'a3b2' → 'aaabb').
Count Substrings
Implement a function that counts non-overlapping occurrences of a substring in a given string.
Most Common Character
Return the character that appears most frequently in a string, breaking ties by earliest occurrence.
Isomorphic Strings Check
Given two strings, check if they are isomorphic by verifying a one-to-one character mapping.
Index of First Occurrence
Implement a function that finds the starting index of a substring within a string, returning -1 when absent.
Error message formatter
Write a function that constructs a formatted error message from a code, an optional context, and a fallback message.
Stack Trace Sanitizer
Implement a function that rewrites traceback file paths to basenames only.
Extract Hashtags
Extract unique hashtags from a given text string in the order they appear.
Extract mentions
Extract unique @mentions from a string, respecting email-like patterns and punctuation.
Validate time format
Check whether a given string is a valid 24-hour time in HH:MM format.
Replace multiple spaces
Implement a function that replaces every sequence of spaces with a single space.
Extract Quoted Strings
Write a function that extracts the text inside every double-quoted substring from a given string.
Split on camelCase
Given a camelCase string, split it into words at uppercase letters and return them as lowercase words.
Extract domain from URL
Extract the domain (hostname without port or www) from a given URL string.
Normalize Whitespace
Write a function that normalizes any whitespace in a string to single spaces and trims the ends.
Strip Leading Zeros
Write a function that strips leading zeros from a string representing a non-negative integer.
Parse key=value pairs
Implement a parser that converts a space-separated 'key=value' string into a Python dictionary, supporting quoted values.
Extract file extensions
Implement a function that extracts the extension from a filename according to standard rules.
Validate username format
Implement a function that validates a username according to length, allowed characters, and no consecutive underscores.
Hamming Distance
Implement a function that computes the Hamming distance between two strings of equal length.
Showing 59 challenges · easy · Strings & Text
Strings & Text — Python coding challenges
What you will find here
This page lists strings & text challenges — real Python problems you solve in the browser IDE with instant test feedback. Each challenge includes a clear brief, starter code, and automated checks.
Challenges vs tutorials and quizzes
Challenges test what you can build under constraints. For guided teaching, use our Python tutorials. For quick checks, try quizzes or copy snippets from code samples.