Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Conversion into CamelCase by Sunshine_in_Winter
def to_camel_case(name: str) -> str:
# define a list variable to store the splitted words
splitted_string = name.split("_")
# define a list variable to store the proceed words
returned_string = []
# iterate the list and cover the first character to a capital one
for item in splitted_string:
for i in range(0, len(item)):
if i == 0:
returned_string.append(item[i].upper())
else:
returned_string.append(item[i])
return "".join(returned_string)
print("Example:")
print(to_camel_case("my_function_name"))
# These "asserts" are used for self-checking
assert to_camel_case("my_function_name") == "MyFunctionName"
assert to_camel_case("i_phone") == "IPhone"
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 3, 2025
Comments: