Created
December 2, 2017 16:44
-
-
Save nara-l/f472bc2e97029fbd85b6f0721bf57240 to your computer and use it in GitHub Desktop.
Convert to Snake case 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
# convert to snake case, added replace - could do better with re https://stackoverflow.com/a/1176023/851056 | |
def convert(name): | |
new_name = name.replace(" ", "").replace("'","") | |
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', new_name) | |
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment