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'api
str2 = 'port_mapping'app
> to_camel_case(str2)it
> portMappingmap
> to_snake_case(str1)word
>port_mappingping