We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent af11152 commit 63d53aaCopy full SHA for 63d53aa
URLify/urlify.py
@@ -0,0 +1,21 @@
1
+"""
2
+Replace all spaces in a string with '%20'
3
+
4
+output - string with spaces replaced with '%20'
5
+input - string
6
+constraints - O(n)
7
+examples - 'John Smith ' => 'John%20Smith'
8
+edge cases
9
+ non-string input => throw an error
10
+ all spaces in a string => return empty string
11
+ more than one space between words => handle them accordingly
12
13
+import re
14
15
+def urlify(inputString):
16
+ # If input is not a string
17
+ if type(inputString) != str:
18
+ # Raise an error
19
+ raise ValueError('Input is not a string')
20
+ # Return RegEx expression that replaces spaces in the string (which has been stripped)
21
+ return re.sub(" ", '%20', inputString.strip())
0 commit comments