MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / to_complex_case

Function to_complex_case

strings/string_switch_case.py:44–77  ·  view source on GitHub ↗

Returns the string concatenated with the delimiter we provide. Parameters: @text: The string on which we want to perform operation @upper: Boolean value to determine whether we want capitalized result or not @separator: The delimiter with which we want to concatenate words

(text: str, upper: bool, separator: str)

Source from the content-addressed store, hash-verified

42
43
44def to_complex_case(text: str, upper: bool, separator: str) -> str:
45 """
46 Returns the string concatenated with the delimiter we provide.
47
48 Parameters:
49 @text: The string on which we want to perform operation
50 @upper: Boolean value to determine whether we want capitalized result or not
51 @separator: The delimiter with which we want to concatenate words
52
53 Examples:
54 >>> to_complex_case("one two 31235three4four", True, "_")
55 'ONE_TWO_31235THREE4FOUR'
56 >>> to_complex_case("one two 31235three4four", False, "-")
57 'one-two-31235three4four'
58 """
59 try:
60 string_split = split_input(text)
61 if upper:
62 res_str = "".join(
63 [
64 separator.join([char.upper() for char in sub_str])
65 for sub_str in string_split
66 ]
67 )
68 else:
69 res_str = "".join(
70 [
71 separator.join([char.lower() for char in sub_str])
72 for sub_str in string_split
73 ]
74 )
75 return res_str
76 except IndexError:
77 return "not valid string"
78
79
80# main content

Callers 2

to_snake_caseFunction · 0.85
to_kebab_caseFunction · 0.85

Calls 1

split_inputFunction · 0.85

Tested by

no test coverage detected