The code you read implements the transformation of variable names to a hump.

The code snippet read here is from 30-seconds-of-Python.

camel

from re import sub

def camel(s) :
  s = sub(r"(_|-)+"."", s).title().replace(""."")
  return s[0].lower() + s[1:]

# EXAMPLES
camel('some_database_field_name') # 'someDatabaseFieldName'
camel('Some label that needs to be camelized') # 'someLabelThatNeedsToBeCamelized'
camel('some-javascript-property') # 'someJavascriptProperty'
camel('some-mixed_string with spaces_underscores-and-hyphens') # 'someMixedStringWithSpacesUnderscoresAndHyphens'
Copy the code

The Camel function takes a variable name as a string and converts it to camel form. Similar to the previous two conversion functions, this function considers strings in the form of variables, with related separations between words, rather than directly contiguous words, such as someFunctionName.

The re.sub function replaces symbolic delimiters in strings with Spaces. Then use str.title() to uppercase the first letter of the word. Use the str.replace function to strip out all the Spaces and connect all the words together. When the function finally returns, it changes the first letter of the string to lowercase. S [1:] extracts slices of the string from subscript 1 to the end.