easy +10 pts

Kebab Case a Phrase

Convert any phrase into a URL-friendly kebab-case string.

Write a function `to_kebab_case(s: str) -> str` that takes a string `s` and returns a URL-friendly kebab-case version. **Rules:** - Convert the entire string to lowercase. - Replace any sequence of non-alphanumeric characters (spaces, punctuation, symbols) with a single hyphen `-`. - Split camelCase boundaries: insert a hyphen between a lowercase letter and an uppercase letter (e.g., `camelCase` -> `camel-case`). - Remove leading and trailing hyphens. - If the result is empty after cleaning, return an empty string. **Examples:** - `"Hello World"` -> `"hello-world"` - `"Hello, World!"` -> `"hello-world"` - `"camelCase"` -> `"camel-case"` - `"--foo--"` -> `"foo"` **Your implementation must be iterative and use only the standard library.**

Constraints

- `0 <= len(s) <= 1000` - The input may contain any Unicode characters, but only ASCII letters and digits are considered alphanumeric for the purpose of kebab-casing. - Time complexity O(n), where n is the length of the string.

Example

>>> to_kebab_case("Hello World")
'hello-world'
>>> to_kebab_case("camelCase")
'camel-case'
>>> to_kebab_case("---strip--me---")
'strip-me'
>>> to_kebab_case("")
''
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

First handle camelCase by inserting a hyphen before each uppercase letter that follows a lowercase letter.
Then use a regex or manual scan to replace any run of non-alphanumeric characters with a single hyphen.
Finally, strip leading/trailing hyphens and lower everything.
Don't forget to return an empty string if no alphanumeric characters remain.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.