Last active
December 2, 2020 16:38
-
-
Save Ksengine/e8b3db21270f3b62d6912075be20acc4 to your computer and use it in GitHub Desktop.
String cases algorithms for python
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 camel_to_snake(str): | |
""" | |
camelCase to snake_case | |
'camelCase' -> 'camel_case' | |
""" | |
return ''.join(map(lambda char:char if char.islower() else "_"+char.lower(), str)) | |
def snake_to_camel(str): | |
""" | |
snake_case to camelCase | |
'snake_case' -> 'snakeCase' | |
""" | |
return ''.join(map(lambda char:char if char.islower() else "_"+char.lower(), str)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment