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.
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).
Kebab Case a Phrase
Implement a function that converts a phrase into lowercase kebab-case, handling spaces, punctuation, and camelCase.
Find all indexes of a substring
Write a function that returns a list of all starting indexes where a substring appears in a string, including overlapping occurrences.
Remove Consecutive Duplicate Letters
Implement a function that removes consecutive duplicate letters from a string, keeping only one occurrence of each run.
Is rotation of another string
Write a function to determine if one string is a rotation of another string.
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.
Caesar Cipher Shift
Write a function that shifts letters in a string by a given amount, preserving case and ignoring non-letters.
Count consonants
Write a function that counts the number of consonant letters in a string.
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.
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.
Capitalize First Letter
Write a function that capitalizes the first letter of each word in a string.
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.
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.
Compress Consecutive Chars
Write a function that compresses a string by replacing runs of identical characters with the character followed by the count.
Expand compressed string
Implement a function that expands run-length encoded strings (e.g., 'a3b2' → 'aaabb').
Find substring index
Implement a function that returns the starting index of the first occurrence of a substring using only basic string indexing and slicing.
Count Substrings
Implement a function that counts non-overlapping occurrences of a substring in a given string.
Sort characters in string
Write a function that sorts the characters in a string and returns the sorted string.
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.
Parse Log Line
Write a function that parses a log line and returns a dictionary with timestamp, level, and message.
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.
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.
Find all numbers in text
Write a function that extracts all standalone integers from a text string using regular expressions.
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.
Replace template variables
Implement a function that replaces {{variable}} placeholders in a string using a dictionary, leaving unknown placeholders intact.
Hamming Distance
Implement a function that computes the Hamming distance between two strings of equal length.
Showing 45 challenges · 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.