Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update p03_urlify.py #250

Closed
wants to merge 1 commit into from
Closed

Update p03_urlify.py #250

wants to merge 1 commit into from

Conversation

Cesarsk
Copy link
Contributor

@Cesarsk Cesarsk commented Aug 17, 2022

I added a check. If there aren't at least two 'whitespace' characters at the end of the input_string, the algorithm doesn't work.

i.e. ("Mr Jo", 5) returns %2

I added a check. If there aren't at least two 'whitespace' characters at the end of the input_string, the algorithm doesn't work.

i.e. ("Mr Jo", 5) returns %2
@@ -5,6 +5,11 @@
def urlify_algo(string, length):
"""replace spaces with %20 and removes trailing spaces"""
# convert to list because Python strings are immutable

# there must be at least two trailing spaces for this algorithm to work
if ord(string[-1]) != ord(string[-2]) != 32:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work since a string may have no spaces. If we did want to enforce this though probably we'd do something like:

if not string.endswith("  "):
    raise ValueError("String needs to end with spaces")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants