-
Notifications
You must be signed in to change notification settings - Fork 172
Closed
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomersincorrect groundtruth
Description
The canonical solution for problem 140 is given by
def fix_spaces(text):
"""
Given a string text, replace all spaces in it with underscores,
and if a string has more than 2 consecutive spaces,
then replace all consecutive spaces with -
fix_spaces("Example") == "Example"
fix_spaces("Example 1") == "Example_1"
fix_spaces(" Example 2") == "_Example_2"
fix_spaces(" Example 3") == "_Example-3"
"""
### Canonical solution below ###
ans = text
for i in range(len(text)-1, 2, -1):
ans = ans.replace(" " * i, "-")
return ans.replace(" ", "_")
Shouldn't it be len(text)
instead?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomersincorrect groundtruth