+ 2
Camel to Snake, Code Coach [Solved]
str = input() for i in range(len(str)): if i != 0: # to avoid first letter if it's capital e.g. CodeCoach if str[i].isupper(): str = str.replace(str[i], '_'+str[i].lower()) print(str.lower()) I have solved Camel to Snake code coach problem, and it passed every Test Cases except Test Case #5. Does anyone knows what in Test Case #5?
7 Réponses
+ 3
Rain Wong Hei Ming
Thank you very much for all your responses, it means a lot.
I've finally solved this problem using python enumerate() built-in function.
Here, I've attached my solution, please review it and let me know if I can make it better.
https://sololearn.com/compiler-playground/cirv9Uqr8WXF/?ref=app
+ 2
What would happen if the string is "ItIsFun"?
+ 2
Are you sure?
Did you tried it with your code?
+ 2
No bad.
But please don't use python keywords as variable name.
If you add another piece of code below your solution, it might produce an error.
example:
<code added below to your original code>
b = 10
print(str(b))
result:
Traceback (most recent call last):
File "./Playground/file0.py", line 18, in <module>
print(str(b))
TypeError: 'str' object is not callable
+ 1
Armash Ansari ,
Test Case #5's input is actually in PascalCase or UpperCamelCase, not camelCase.
+ 1
Armash Ansari ,
It looks well organized.
+ 1
Wong Hei Ming,
Good point,
I've replaced variable name 'str' to 'camel'. I think that'd be more related and won't create problems if I add another piece of code below it.