We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7ca5ea0 commit fb23fbfCopy full SHA for fb23fbf
urlify.py
@@ -0,0 +1,32 @@
1
+
2
+def urlify(string, length):
3
+ i = 0
4
+ spaces = 0
5
+ while i < length:
6
+ if string[i] == " ":
7
+ spaces = spaces + 1
8
+ i = i + 1
9
+ i = length - 1
10
+ prev_i = length - 1
11
+ while i >= 0:
12
13
+ while i < prev_i:
14
+ string[prev_i + 2 * spaces] = string[prev_i]
15
+ prev_i = prev_i - 1
16
+ string[prev_i + 2 * spaces] = "0"
17
+ string[prev_i + 2 * spaces - 1] = "2"
18
+ string[prev_i + 2 * spaces - 2] = "%"
19
+ spaces = spaces - 1
20
+ prev_i = i - 1
21
+ i = i - 1
22
+ return "".join(a for a in string)
23
24
+def main():
25
+ string = "Mr John Smith"
26
+ length = 13
27
+ input_string = [a for a in string] + [" " for _ in xrange(4)]
28
+ url = urlify(input_string, length)
29
+ print(url)
30
31
+if __name__ == "__main__":
32
+ main()
0 commit comments