0

CamelCase to snake_case

a = input() #camelCaseDoing to camel_case_doing ac = a[0] for x in a[1:]: if (x.isalpha() and x.upper() == x): x = '_' + x.lower() ac += x print(ac)

21st Jan 2023, 1:03 PM
Sanjay Sahu
Sanjay Sahu - avatar
5 ответов
+ 1
Hi Sanjay Sahu there is a hint in the task. If the first letter is upper it shouldn't take an underscore. Your code actually is missing the case if the first letter is capital.
21st Jan 2023, 1:55 PM
JuZip
+ 1
Oh yeah I didn't notice that, great you found what to do yourself 👍
21st Jan 2023, 2:29 PM
JuZip
0
This code passes first 4 tests, but not the 5th one..!!
21st Jan 2023, 1:04 PM
Sanjay Sahu
Sanjay Sahu - avatar
0
Julian Zimpel Thanks for your response..! I had actually taken the first letter as is through following variable declaration: ac = a[0] I was converting uppercase letter into _+lowercase from 2nd letter onwards.. I've now rectified my code by changing the above line of code into: ac = a[0].lower () Finally, the code has been able to pass all tests..!!
21st Jan 2023, 2:16 PM
Sanjay Sahu
Sanjay Sahu - avatar
0
Hi Julian Zimpel , your remarks actually gave me the much needed insight for rectifying the code.
21st Jan 2023, 2:49 PM
Sanjay Sahu
Sanjay Sahu - avatar