Skip to content

Instantly share code, notes, and snippets.

@vu3jej
Created September 21, 2016 15:23
Show Gist options
  • Save vu3jej/56057e2d17bf16302429ffefdcc5ea7c to your computer and use it in GitHub Desktop.
Save vu3jej/56057e2d17bf16302429ffefdcc5ea7c to your computer and use it in GitHub Desktop.
camelCase ==> snake_case
def slytherin(string):
"""Convert & return strings in camelCase to snake_case"""
tmp = re.sub(pattern=r'(.)([A-Z][a-z]+)', repl=r'\1_\2', string=string)
return re.sub(pattern=r'([a-z0-9])([A-Z])', repl=r'\1_\2', string=tmp)\
.lower()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment