Created
December 16, 2023 18:45
-
-
Save fhsinchy/32c63d619e583b26f9a2a64759b24eaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_to_snake_case(pascal_cased_string): | |
# snake_cased_char_list = [pascal_cased_string[0].lower()] | |
# for char in pascal_cased_string[1:]: | |
# if char.isupper(): | |
# snake_cased_char_list.append(f'_{char.lower()}') | |
# else: | |
# snake_cased_char_list.append(char) | |
snake_cased_char_list = [f'_{char.lower()}' if char.isupper() else char for char in pascal_cased_string] | |
return ''.join(snake_cased_char_list).strip('_') | |
def main(): | |
pascal_cased_string = 'aLongAndComplexString' | |
print(convert_to_snake_case(pascal_cased_string)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment