Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
2 Solutions: 1. regex and 2. one-liner solution in Clear category for Conversion into CamelCase by H0r4c3
import re
def to_camel_case_2(name: str) -> str:
regex = '([A-Z])([a-z])'
name = re.sub(regex, 'r\1\_2', name).capitalize()
return name
def to_camel_case(name: str) -> str:
return ''.join([item.capitalize() for item in name.split('_')])
if __name__ == '__main__':
print("Example:")
print(to_camel_case('name'))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert to_camel_case("my_function_name") == "MyFunctionName"
assert to_camel_case("i_phone") == "IPhone"
assert to_camel_case("this_function_is_empty") == "ThisFunctionIsEmpty"
assert to_camel_case("name") == "Name"
print("Coding complete? Click 'Check' to earn cool rewards!")
Dec. 18, 2021
Comments: