This repository was archived by the owner on Jul 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -205,3 +205,31 @@ def get_longest_uniq_length(origin: str, /) -> int:
205205 length = max (length , right_idx - left_idx + 1 )
206206
207207 return length
208+
209+
210+ def add_spaces (origin : str ) -> str :
211+ """
212+ Return modified string with whitespaces before capital letters
213+
214+ An origin string may contain letters in upper case. The function removes
215+ any white spaces present in the initial data, and transform the string
216+ in a way to add spaces only before letters in upper case.
217+
218+ :param origin: an original string
219+ :rtype: str
220+
221+ :return: string with white spaces before capital letters
222+ :rtype: str
223+
224+ Usage:
225+
226+ >>> assert add_spaces("camelCase") == "camel Case"
227+ >>> assert add_spaces(" John Doe ") == "John Doe"
228+ >>> assert add_spaces("racecar") == "racecar"
229+
230+ """
231+
232+ # remove white spaces, if any
233+ origin = origin .replace (" " , "" )
234+
235+ return "" .join (f" { c } " if c .isupper () else c for c in origin ).lstrip ()
Original file line number Diff line number Diff line change @@ -70,3 +70,10 @@ def test_get_longest_uniq_sequence_length():
7070 assert sequences .get_longest_uniq_length ("abcdefg" ) == 7
7171 assert sequences .get_longest_uniq_length ("abcacba" ) == 3
7272 assert sequences .get_longest_uniq_length ("hwccjayhiszbmomlqkem" ) == 11
73+
74+
75+ def test_add_space ():
76+ assert sequences .add_spaces ("" ) == ""
77+ assert sequences .add_spaces ("test_test" ) == "test_test"
78+ assert sequences .add_spaces ("JohnDoe" ) == "John Doe"
79+ assert sequences .add_spaces ("John Doe" ) == "John Doe"
You can’t perform that action at this time.
0 commit comments