+ 2

Where is the error?

code coach The Spy Life. Output must include just alphabetical characters https://code.sololearn.com/cuu7jl7ZQwUr/?ref=app

3rd Mar 2020, 6:19 PM
meow
meow - avatar
11 Antworten
+ 4
You broke a golden rule: Never ever remove elements from a list while iterating it. Copy word to word1 Iterate word1 delete from word or use filter, if you are familiar with it.
3rd Mar 2020, 6:42 PM
Oma Falk
Oma Falk - avatar
+ 3
Alexandr Thank you I solved the problem but what does it mean why you add that?
3rd Mar 2020, 6:57 PM
meow
meow - avatar
+ 2
Oma Falk if i am not mistaken you can in fact remove while iterating if you iterate from end to start, which prevents the skipping. unsure if it is advisable to do so... 😅😅😅
3rd Mar 2020, 6:48 PM
Burey
Burey - avatar
+ 2
Burey my Dad - who was a source of wise words - once teached me: "No bug can be too big that it cant be repaired by an even bigger bug" 😁😁😁😁
3rd Mar 2020, 6:58 PM
Oma Falk
Oma Falk - avatar
+ 2
s=input() for j in range(len(s)-1,-1,-1): if(s[j].isalpha() or s[j]==" "): print(s[j],end="")
5th Mar 2020, 2:17 PM
MULUKUTLA. JYOTSNA MANASA
+ 1
Oma Falk i can't argue with that 🤣🤣🤣
3rd Mar 2020, 7:09 PM
Burey
Burey - avatar
+ 1
1. Why do you reverse the list two times? 2. Why do you convert string to list (and then make another string out of the list just to print it)? 3. You miss the space ('\s') in the list. 4. Why is there `a=0` in the code? You can just use a string and remove chars from it, i.e. replace it with nothing: ``` for i in word: if(i not in list): word = word.replace(i, '') ``` (and then print it). Here is my solution: https://code.sololearn.com/crr5zo9SXEMG/
4th Mar 2020, 10:36 PM
Hrvoje
Hrvoje - avatar
0
Alexandr but the part which is I didn't understand is why this changed result. The items in list is same and name also but result different why?
3rd Mar 2020, 7:26 PM
meow
meow - avatar
0
Hrvoje this is nice code but I dont love using librarys
5th Mar 2020, 1:34 AM
meow
meow - avatar
0
meow , OK, then still you can use only string, no need for list, and you have to add space to the alphabet, plus reverse the string only once. :)
5th Mar 2020, 8:31 AM
Hrvoje
Hrvoje - avatar
0
Hrvoje Thanks for your advices :)
5th Mar 2020, 1:22 PM
meow
meow - avatar