Complete the code to create a URL slug by replacing spaces with {{BLANK_1}}.
slug = title.replace(' ', '[1]')
Hyphens (-) are the standard and recommended character to replace spaces in URL slugs because they improve readability and SEO.
Complete the code to convert the slug to lowercase for better URL consistency.
slug = slug.[1]()capitalize() which only changes the first letterupper() which makes letters uppercaseUsing lower() converts all characters to lowercase, which is best practice for URL slugs to avoid duplicates and improve SEO.
Fix the error in the code to remove special characters from the slug using {{BLANK_1}}.
import re slug = [1](r'[^a-z0-9-]', '', slug)
re.match which only checks the start of the stringre.search which finds but does not replacere.split which splits the string instead of replacingre.sub replaces all characters not matching the pattern with an empty string, effectively removing special characters from the slug.
Fill both blanks to create a slug dictionary with keys as original titles and values as optimized slugs.
slug_dict = {title: title[1]().replace(' ', '[2]') for title in titles}Using .lower() converts titles to lowercase and replacing spaces with hyphens - creates SEO-friendly slugs.
Fill all three blanks to filter titles longer than 5 characters and create slugs with lowercase and hyphens.
filtered_slugs = {title[1]: title[2]().replace(' ', '[3]') for title in titles if len(title) > 5}.strip() removes extra spaces around the title, .lower() converts to lowercase, and replacing spaces with hyphens - creates clean, SEO-friendly slugs.