+ 2
Where is the error?
code coach The Spy Life. Output must include just alphabetical characters https://code.sololearn.com/cuu7jl7ZQwUr/?ref=app
11 Respuestas
+ 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.
+ 3
Alexandr Thank you I solved the problem but what does it mean why you add that?
+ 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... 😅😅😅
+ 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"
😁😁😁😁
+ 2
s=input()
for j in range(len(s)-1,-1,-1):
if(s[j].isalpha() or s[j]==" "):
print(s[j],end="")
+ 1
Oma Falk i can't argue with that 🤣🤣🤣
+ 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/
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?
0
Hrvoje this is nice code but I dont love using librarys
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. :)
0
Hrvoje Thanks for your advices :)