File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Python/chapter01/1.1 - Is Unique Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python3
2
+ '''
3
+ Module that Write a method to replace all spaces in a string with '%20'. You may assume that the string
4
+ has sufficient space at the end to hold the additional characters, and that you are given the "true"
5
+ length of the string. (Note: If implementing in Java, please use a character array so that you can
6
+ perform this operation in place.)
7
+ '''
8
+
9
+ import unittest
10
+
11
+ def URLify (string , char ):
12
+ '''
13
+ Function that replace all spaces in a string with '%20'.
14
+ Args:
15
+ string (str): a string to modify
16
+ '''
17
+ return string [:char + 1 ].replace (" " , "%20" )
18
+
19
+ class Test (unittest .TestCase ):
20
+ def test1 (self ):
21
+ input_string = "Mr Johns Smith "
22
+ char = 13
23
+ output_string = "Mr%20John%20Smith"
24
+
25
+ self .assertTrue (URLify (input_string , 13 ), output_string )
26
+
27
+ if __name__ == '__main__' :
28
+ unittest .main ()
You can’t perform that action at this time.
0 commit comments