easy +5 pts

Replace Spaces with Dashes

Transform a string by converting every space into a dash.

Write a function `dashify(text)` that takes a string `text` and returns a new string where every space character (`' '`) is replaced by a dash (`'-'`). The function must preserve all other characters exactly as they are.

Constraints

- Input can be an empty string. - Input may contain multiple consecutive spaces. - Input may contain leading or trailing spaces. - No other characters are modified. - Time complexity: O(n), where n is the length of the input string. - Space complexity: O(n) for the output.

Example

```python
>>> dashify("hello world")
'hello-world'
>>> dashify("  multiple   spaces  ")
'--multiple---spaces--'
>>> dashify("")
''
```
5 points ~5 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Python strings have a built-in method to replace all occurrences of a substring.
The replace method returns a new string; it does not modify the original.
Make sure to handle the empty string gracefully.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.