Overview
Real-world text is messy. Clean it up with Python's built-in string methods and build new text with f-strings.
- lower(), strip(), split() and join()
- Checking characters with isalnum() and isspace()
- f-strings for formatting
Short Course
Strings come with methods that return a new string — the original never changes. Chain them to clean text step by step.
name = " ada LOVELACE "
clean = name.strip().title() # 'Ada Lovelace'
words = clean.split() # ['Ada', 'Lovelace']
"-".join(words) # 'Ada-Lovelace'
"py3".isalnum() # True
f"Hi {clean}, {len(words)} names"
Task
Write slugify(title) that turns a title into a URL slug: lowercase, words
joined by single hyphens, and every character that isn't a letter, digit or
space removed.
Test Suites
Pending
Stdout