[Solved] Code Challenge: Camel to Snake | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[Solved] Code Challenge: Camel to Snake

This code works for all case tests except for #5. Can anybody please help me to point out what is the flaw in the code below? Thanks in advance. https://sololearn.com/compiler-playground/c2g1g1YEy95Z/?ref=app

24th Mar 2024, 1:28 PM
Shreyash Roopnah
Shreyash Roopnah - avatar
4 Answers
+ 2
Shreyash Roopnah , Some people put [Solved] in the title after. Your code satisfies the requirements but seems overly convoluted and inefficient to me. Just one example, instead of checking x != 0 every iteration, you could just start your range at 1 (but I wouldn't even use range).
25th Mar 2024, 6:02 AM
Rain
Rain - avatar
+ 1
Just got it! There was actually a mistake in line 5... It should actually be x!=0 not x!=1...
24th Mar 2024, 1:32 PM
Shreyash Roopnah
Shreyash Roopnah - avatar
0
Rain , Thanks for the tip! I am pretty new to these functions (which I learnt last month in my Python Developer course, which I just recently finished) , so I just tried my best to solve this code challenge... Sometimes, I agree that my codes are usually longer than necessary while others are pretty short, for example, in the Déjà Vu code challenge it is as follows: char_set=set() string=input() for x in string: char_set.add(x) if len(char_set)==len(string): print("Unique") else: print("Deja Vu")
25th Mar 2024, 2:01 PM
Shreyash Roopnah
Shreyash Roopnah - avatar
0
Shreyash Roopnah, Congrats for finishing Python Developer. Efficiency should come with practice. Your second code, while short, could be even shorter too. When you come from other languages (like Java) to Python, it can take a while to realize how little you need to type to get the same job done, and truly start thinking "pythonically". Python doesn't make you declare variables before you use them, and you don't have to assemble a new iterable item by item if all you want to do is copy it to a new type. You can just call the constructor of the new type with the iterable as an argument, and it'll return the new iterable. string = input() if len(string) == len(set(string)): print("Unique") else: print("Deja Vu")
25th Mar 2024, 4:47 PM
Rain
Rain - avatar