Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Not elegant, but it works anyway :) solution in Uncategorized category for Conversion from CamelCase by rettrus
def from_camel_case(name):
new_list = []
for i in name:
if str(i).isupper():
new_list.append('_')
new_list.append(i.lower())
else:
new_list.append(i)
str_list = str(new_list)
str_dirty = str_list.lstrip("['_',")
str_clean = str_dirty.replace("'", '').replace("]", '').replace(",", '').replace(" ", '')
return str_clean
if __name__ == '__main__':
print("Example:")
print(from_camel_case("IPhone"))
#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!")
April 1, 2021
Comments: