+ 1
Pig Latin Error
I am enable to understand what's the difference between: a = input().lower() x = a.split() z = [] for i in x: y = i[0] i = i.replace(i[0], "") z.append(i+y+"ay") z = ' '.join(map(str,z)) print(z) And sentence = input() new_sentence = "" for word in sentence.split(): new_word = word[1:] + word[0] + "ay " new_sentence = new_sentence + new_word print(new_sentence) Code. for pig Latin. The Sololearn is giving error to the 1st code in 3rd and 5th hidden test cases. But in second code Sololearn isn't giving any error. What's the problem??
4 Antworten
+ 5
Hi, Prathmesh Angad Phad !
Using replace can change the word in an unexpected way, if the character is included multiple times in the word. Try using slices to modify the word instead.
+ 1
There is no user able to view the hidden case, so we cannot justify.
There maybe some edge cases in 3rd and 5th test case.
Maybe you can send a bug report to SoloLearn?
Actually, I think the second code wouldn't pass any test case because there is a tailing space at the end.
+ 1
Per Bratthammar
I forgot about that.
Maybe adding the 3rd argument will work.
+ 1
Prathmesh Angad Phad ,
Just a side note, you never need to convert the return value of input() to str, because input() returns str.