Skip to content

Instantly share code, notes, and snippets.

@dkapitan
Created October 12, 2015 08:24
Show Gist options
  • Save dkapitan/5578820fbe1d0bfa07a7 to your computer and use it in GitHub Desktop.
Save dkapitan/5578820fbe1d0bfa07a7 to your computer and use it in GitHub Desktop.
Python data munging
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