generate_slug(title) that turns an article title into a clean, URL-friendly slug: lowercase, spaces/underscores turned into hyphens, all other punctuation dropped, and no repeated or leading/trailing hyphens.title = ' Top 10 Python Tips & Tricks!! '
'top-10-python-tips-tricks'
Whitespace trimmed, letters lowercased, spaces become hyphens, "&" and "!" are dropped, and the resulting double hyphen collapses to one.
Strip and lowercase first.
Keep alphanumeric characters as-is; map spaces/underscores/hyphens to a single hyphen; drop everything else.
Collapse '--' to '-' in a loop, then strip leading/trailing hyphens.