This action will force synchronization from 编程语言算法集/Python, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
import re"""general info:https://en.wikipedia.org/wiki/Naming_convention_(programming)#Python_and_Rubypascal case [ an upper Camel Case ]: https://en.wikipedia.org/wiki/Camel_casecamel case: https://en.wikipedia.org/wiki/Camel_casekebab case [ can be found in general info ]:https://en.wikipedia.org/wiki/Naming_convention_(programming)#Python_and_Rubysnake case: https://en.wikipedia.org/wiki/Snake_case"""# assistant functionsdef split_input(str_: str) -> list:""">>> split_input("one two 31235three4four")[['one', 'two', '31235three4four']]"""return [char.split() for char in re.split(r"[^ a-z A-Z 0-9 \s]", str_)]def to_simple_case(str_: str) -> str:""">>> to_simple_case("one two 31235three4four")'OneTwo31235three4four'>>> to_simple_case("This should be combined")'ThisShouldBeCombined'>>> to_simple_case("The first letters are capitalized, then string is merged")'TheFirstLettersAreCapitalizedThenStringIsMerged'>>> to_simple_case("special characters :, ', %, ^, ,ドル are ignored")'SpecialCharactersAreIgnored'"""string_split = split_input(str_)return "".join(["".join([char.capitalize() for char in sub_str]) for sub_str in string_split])def to_complex_case(text: str, upper: bool, separator: str) -> str:"""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 wordsExamples:>>> to_complex_case("one two 31235three4four", True, "_")'ONE_TWO_31235THREE4FOUR'>>> to_complex_case("one two 31235three4four", False, "-")'one-two-31235three4four'"""try:string_split = split_input(text)if upper:res_str = "".join([separator.join([char.upper() for char in sub_str])for sub_str in string_split])else:res_str = "".join([separator.join([char.lower() for char in sub_str])for sub_str in string_split])return res_strexcept IndexError:return "not valid string"# main contentdef to_pascal_case(text: str) -> str:""">>> to_pascal_case("one two 31235three4four")'OneTwo31235three4four'"""return to_simple_case(text)def to_camel_case(text: str) -> str:""">>> to_camel_case("one two 31235three4four")'oneTwo31235three4four'"""try:res_str = to_simple_case(text)return res_str[0].lower() + res_str[1:]except IndexError:return "not valid string"def to_snake_case(text: str, upper: bool) -> str:""">>> to_snake_case("one two 31235three4four", True)'ONE_TWO_31235THREE4FOUR'>>> to_snake_case("one two 31235three4four", False)'one_two_31235three4four'"""return to_complex_case(text, upper, "_")def to_kebab_case(text: str, upper: bool) -> str:""">>> to_kebab_case("one two 31235three4four", True)'ONE-TWO-31235THREE4FOUR'>>> to_kebab_case("one two 31235three4four", False)'one-two-31235three4four'"""return to_complex_case(text, upper, "-")if __name__ == "__main__":__import__("doctest").testmod()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。