def to_camel_case(snake_str): words = snake_str.split('_') return words[0] + ''.join(w.capitalize() for w in words[1:])def to_snake_case(camel_str): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel_str) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
str1 = 'portMapping'
str2 = 'port_mapping'
> to_camel_case(str2)
> portMapping
> to_snake_case(str1)
>port_mapping