runtime
57 / 500
question 57 Strings & Text · medium

A web address for a product

Runtime Market builds each product page's web address from the product's name, as a *slug* such as deluxe-pillow-blue-2-pack. Lower-case the name. Keep the letters a–z and the digits 0–9. Turn each space or dash into a single -, but never put two - in a row and never start the slug with one. Drop every other character, then remove a - left at the end.

Inputname, a product name
Keepa–z and 0–9 after lower-casing
Separatorsa space or - becomes -, unless the slug is still empty or already ends with -
Printsthe slug, with no - at either end
Examples"Deluxe Pillow (Blue) 2-Pack" → deluxe-pillow-blue-2-pack; " Mini Knife Set " → mini-knife-set
Expected output1 line
  1. 1deluxe-pillow-blue-2-pack

Loading your progress…

A web address for a product — Python practice · Runtime