practicepython.in
python exercises
171 exercises

Text wrangling

Turning human text into machine text and back: regular expressions where they earn their place, and splitting where the separator can legitimately appear inside the value.

12 exercisesdifficulty 1–4~232 min in total
Show only the last four string repetition, negative slicing ~12 min camelCase to snake_case re.sub with backreferences, two passes ~20 min Titles into URL slugs regular expressions, re.sub ~15 min Back the other way, without flattening the capitals capitalize() lowercases the rest, leading underscores ~16 min Shorten text without cutting a word in half rsplit, slicing ~15 min The words people actually used tokenising, Counter ~18 min Finding the addresses in a wall of text findall, greedy boundaries ~22 min Marking the words somebody searched for re.escape, alternation order ~22 min Parse a key=value string str.split with maxsplit, skipping empties ~20 min Getting the text out of the markup greedy versus lazy matching, entity decoding order ~22 min Breaking a paragraph into lines greedy algorithms, accumulating a buffer ~22 min The comma that is not a separator character scanning, state machines ~28 min