Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Conversion from CamelCase by ZweiStein
import re
def from_camel_case(name):
"""
Args:
name: CamelCaseName
Must not contain any numeric or special characters
Returns:
underscore_name
Looks for one lowercase/uppercase letter (group 1) followed by
a uppercase letter (group 2)
replaces the result group1 + _ + group2
"""
return re.sub(r"([a-zA-Z])([A-Z])",r"\1_\2" , name).lower()
if __name__ == '__main__':
print("Example:")
print(from_camel_case("Name"))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert from_camel_case("MyFunctionName") == "my_function_name"
assert from_camel_case("IPhone") == "i_phone"
assert from_camel_case("ThisFunctionIsEmpty") == "this_function_is_empty"
assert from_camel_case("Name") == "name"
print("Coding complete? Click 'Check' to earn cool rewards!")
June 12, 2019