Last active
November 30, 2018 01:32
-
-
Save stfuchs/074b6bf9b2b24f77d54ac6b293388620 to your computer and use it in GitHub Desktop.
Convert between camel and snake
This file contains hidden or 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
# Credit: | |
# https://stackoverflow.com/questions/19053707/converting-snake-case-to-lower-camel-case-lowercamelcase | |
# https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case/32064723 | |
import re | |
def camel_to_snake(s): | |
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', re.sub('(.)([A-Z][a-z]+)', r'\1_\2', s)).lower() | |
def snake_to_camel(s): | |
return "".join((x.capitalize() for x in s.split('_'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment