runtime
213 / 500
question 213 Modules & Packages · easy

A slugs module for URLs

Product pages need URL-friendly names ("slugs"), and the shop, the blog and the sitemap all make them. Write this file as the shared slugs module with one function, slugify(title). Check calls it directly and also imports the file as slugs.

Modulethis file, imported as slugs
Functionslugify(title): lower case; every run of characters that aren't letters or digits (spaces, punctuation, underscores) becomes one -; no - at either end
Lettersaccented and non-English letters count as letters: Crème → crème
Exampleslugify('Tea set, "Royal" edition') → 'tea-set-royal-edition'
Examples
callslugify('Deluxe Pillow')returns'deluxe-pillow'
callslugify('Tea set, "Royal" edition')returns'tea-set-royal-edition'
callslugify(' Crème brûlée kit! ')returns'crème-brûlée-kit'

Loading your progress…

A slugs module for URLs — Python practice · Runtime