Skip to content

Instantly share code, notes, and snippets.

View nara-l's full-sized avatar

Lawrence Nara nara-l

View GitHub Profile
@nara-l
nara-l / convert_to_snake_case
Created December 2, 2017 16:44
Convert to Snake case Python
# 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()