Skip to content

Instantly share code, notes, and snippets.

@Ksengine
Last active December 2, 2020 16:38
Show Gist options
  • Save Ksengine/e8b3db21270f3b62d6912075be20acc4 to your computer and use it in GitHub Desktop.
Save Ksengine/e8b3db21270f3b62d6912075be20acc4 to your computer and use it in GitHub Desktop.
String cases algorithms for python
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