Learning map · Track 7 · intermediate
Working with Text
Names typed into forms, product codes on labels, prices in a supplier's list, lines in a server log, messages from a support inbox: most of the data a program meets arrives as text, and almost none of it arrives clean. This track turns strings from something you print into something you can process with confidence. You will look closely at how strings behave, then clean messy input with strip, case and replace methods, split delimited text into fields and join it back, search and count inside text, and write validators for PIN codes, product codes, email addresses and phone numbers. You will format aligned reports and wrapped paragraphs, parse settings files, log lines and simple comma-separated data, and learn regular expressions step by step: matching, character classes and quantifiers, then groups, findall and substitution. A lesson on Unicode explains code points, UTF-8 bytes, normalisation and case-folding, with Arabic and accented examples.
The track is written for learners who already know variables, conditions, loops, functions and the core data structures (lists, tuples, dictionaries and sets). Every lesson uses realistic situations, such as customer records, invoices, receipts and delivery notes, and every exercise is checked automatically, including the awkward cases real data contains: empty strings, stray spaces, mixed capitals and non-English text. It ends with a mini project in five milestones: a web-server log analyzer that parses each line with a regular expression, counts status codes, ranks pages, charts traffic by hour and prints a formatted daily report.
By the end of this track you can
- Clean and normalise messy user input with string methods, including whitespace, case, prefixes and thousands separators
- Parse delimited text, settings files and log lines into lists and dictionaries, skipping damaged lines safely
- Write validators for real formats with character tests and regular expressions, aware of Unicode digits and letters
- Extract and rewrite text with regular expression groups, findall, finditer and re.sub
- Produce aligned tables, invoices and wrapped paragraphs with format specifications, str.format() and textwrap
- Convert between text and bytes with UTF-8 and compare text reliably with normalisation and casefold()
Lessons
- 1Strings in depthHow Python strings really behave: immutability, indexing and slicing, looping over characters, escape sequences and raw strings.35 min · 4 exFree
- 2Cleaning messy textTidy user-entered text with the strip family, case methods, replace, removeprefix and whitespace normalisation.35 min · 4 exMembers
- 3Splitting and joining textBreak delimited text into fields with split, rsplit, maxsplit and partition, and build text back up with join.35 min · 4 exMembers
- 4Searching inside textLocate and count text with in, find, rfind, index and count, and check beginnings and endings with startswith and endswith.35 min · 4 exMembers
- 5Validating textCheck that input has the right shape using isdigit, isalpha and friends (and their Unicode caveats), then combine small checks into validators.45 min · 4 exMembers
- 6Formatting text reportsProduce aligned tables and tidy reports with format specifications, str.format(), multi-line strings and the textwrap module.45 min · 4 exMembers
- 7Parsing structured textTurn settings files, log lines and simple comma-separated data into Python dictionaries and lists, line by line, and see where hand-written parsing stops working.45 min · 4 exMembers
- 8Regular expressions: the basicsDescribe text patterns with regular expressions and test them with re.search, re.match and re.fullmatch, using character classes, quantifiers and anchors.50 min · 4 exMembers
- 9Regex groups, findall and substitutionExtract parts of a match with numbered and named groups, find every match with findall and finditer, rewrite text with re.sub, and adjust matching with flags.55 min · 5 exMembers
- 10Unicode and encodingsUnderstand characters as Unicode code points, convert between text and bytes with UTF-8, and compare text reliably with normalisation and case-folding.45 min · 4 exMembers
- 11Mini project: web log analyzerBuild a small analyzer for a web-server access log in five milestones: parse lines with a regex, count status codes, rank pages, chart traffic by hour and print a formatted report.75 min · 5 exMembers