Created
October 12, 2015 08:24
-
-
Save dkapitan/5578820fbe1d0bfa07a7 to your computer and use it in GitHub Desktop.
Python data munging
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
import re | |
first_cap_re = re.compile('(.)([A-Z][a-z]+)') | |
all_cap_re = re.compile('([a-z0-9])([A-Z])') | |
def convert(name): | |
s1 = first_cap_re.sub(r'\1_\2', name) | |
return all_cap_re.sub(r'\1_\2', s1).lower() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment