I am learning Python and got stucked on one of the exercises. We have to convert camelCase into snake_case. I tried with a conditional in a loop:
camelCase = input("camelCase: ")
for c in camelCase:
if c.islower():
return c
elif c.isupper():
return ("_" + c.lower())
print("snake_case:" + c)
But I realized I didn´t understand how return works.
Now I tried making a list:
camelCase = input("camelCase: ")
snake_case = []
for c in camelCase:
if c.islower():
snake_case.append(c)
elif c.isupper():
snake_case.append("_" + c.lower())
print("snake_case:", snake_case)
But I don´t know how to get it like a string (word), it comes out like that.
camelCase: firstName
snake_case: ['f', 'i', 'r', 's', 't', '_n', 'a', 'm', 'e']