It can be a bit shorter:
def cc2jl(s):
return "".join(["_"+l if i and l.isupper() and not s[i-1:i+2].isupper() else l for i, l in enumerate(s)]).lower()
Regular Expression Alternative:
rx = re.compile(r"(?<=.)(((?<![A-Z])[A-Z])|([A-Z](?=[a-z])))")
def cc2jl(s):
return rx.sub("_\\1", s).lower()