Editor

Python string exercises

Python string problems, from slicing and formatting to parsing text, each checked by tests in your browser.

Beginner

  1. 2. Say HelloA personal greeting25 XP2 min
  2. 7. Capitalize WordsGive every word a capital letter35 XP3 min
  3. 10. Reverse a StringText, back to front40 XP3 min
  4. 12. Count VowelsHow many vowels hide in the text?45 XP5 min
  5. 30. Missing LettersWhich letters of the alphabet never show up in this sentence?30 XP6 min
  6. 33. Reverse the Word OrderRead a sentence back to front, one whole word at a time30 XP5 min
  7. 34. Caesar CipherSlide every letter along the alphabet to hide a message35 XP8 min
  8. 202. InitialsA whole name squeezed into a few letters25 XP4 min
  9. 208. Word CountHow long is this essay, really?25 XP3 min
  10. 222. Mask an Email AddressShow enough of an email address to recognise it, and no more30 XP5 min
  11. 227. Snake Case to Camel CaseRename a Python variable for a JavaScript teammate30 XP5 min
  12. 247. Censor Banned WordsKeep the comments clean without mangling innocent words40 XP8 min
  13. 256. Title Case With Small WordsMake a book title look the way publishers print it40 XP8 min
  14. 504. Count a WordHow often does a word turn up, capital letters or not?25 XP3 min
  15. 517. Shorten Long WordsWhy programmers write i18n instead of internationalization25 XP3 min
  16. 521. Text Without VowelsSqueeze a message down by dropping every vowel25 XP3 min
  17. 522. The Longest WordFind the word in a sentence that takes the most letters to spell25 XP4 min
  18. 523. The Middle LetterWhat sits right at the center of a word?25 XP4 min
  19. 528. Vowels and ConsonantsSplit the letters of a sentence into two groups and count them25 XP4 min
  20. 530. Add Up the ScoresTwelve plus seven should never come out as one hundred and twenty-seven30 XP4 min
  21. 538. Count the Character TypesCapitals, small letters, digits and spaces: a head count for a string30 XP5 min

Intermediate

  1. 17. Palindrome CheckDoes it read the same backwards?60 XP6 min
  2. 53. Longest Common PrefixThe longest beginning that every word in the list agrees on55 XP8 min
  3. 57. Compress Repeated LettersSqueeze runs of repeated letters, but only when it saves space60 XP10 min
  4. 65. Roman Numerals to IntegerWhat number is MCMXCIV hiding?60 XP9 min
  5. 68. Integer to Roman NumeralsWrite any year the way the Romans carved it in stone65 XP10 min
  6. 94. Rail Fence CipherZigzag a secret message across rails, then read it off row by row75 XP14 min
  7. 101. Most Frequent WordsFind the words a piece of writing leans on the most80 XP15 min
  8. 263. Same Letter PatternDo egg and add share a secret shape?55 XP8 min
  9. 282. Look and Say1, 11, 21, 1211: what comes next?65 XP12 min
  10. 312. Word WrapFit paragraphs into a narrow column without splitting a word70 XP14 min
  11. 314. Camel Case to Snake CaseBring Java-style names into Python style, acronyms and all75 XP14 min
  12. 579. Anagram CheckIs one phrase a rearrangement of another?60 XP7 min
  13. 584. Password RulesA password checker that lets the weak ones through60 XP8 min
  14. 627. Quiz Marker With FeedbackMark a class quiz fairly, even when answers are typed a little differently155 XP50 min

Advanced

  1. 137. Longest Palindromic SubstringSomewhere inside this string is its longest mirror image125 XP25 min
  2. 155. Number to English WordsSpell out any number the way you would say it aloud140 XP30 min
  3. 165. Shortest PalindromeAdd as few letters as possible to the front to make it read both ways155 XP30 min
  4. 345. Replace and Keep the CaseFind and replace that respects SHOUTING, Titles and lowercase115 XP20 min
  5. 355. Shortest Unique PrefixesHow few letters does it take to tell each word apart?120 XP20 min
  6. 388. Match the AbbreviationsWhich words could i18n stand for?140 XP30 min
  7. 409. Find Every OccurrenceFind every place a marker appears in a genome-sized text150 XP30 min
  8. 430. Longest Repeated SubstringThe longest piece of text that shows up twice175 XP35 min

Expert

  1. 177. Justify TextLay out words in tidy lines that touch both margins, like a newspaper210 XP40 min
  2. 195. Glob Pattern MatchingWhich file paths does a pattern full of stars and question marks pick out?260 XP50 min
  3. 446. Palindrome PairsWhich two words glue together into a palindrome?220 XP45 min
  4. 467. Line-by-Line DiffWhat changed between two versions of a file?240 XP50 min

Other topics

Or see every challenge, with study plans, today's challenge and duels.