+ 1
Is there a way to do this more efficiently? Spylife
6 Réponses
+ 3
Tarun Kumar Aggarwal
Instead of making a list of alphabets, you can simply use str.isalpha() to check if a character is an alphabet.
https://code.sololearn.com/cys855C11tXa/?ref=app
There is also a one-line way to do the using the filter() function, but I'm guessing you're not familiar with it currently.
+ 1
XXX
You're right. But for this special code coach use case, you have also to consider the "blank"
if char.isalpha() or char==' ':
0
What are you trying to do here? Are you simply trying to reverse a string. Then the for-loop is unnecessary. Only `codedtext[::-1]` is enough.
0
This is an exercise in code coach. The input string will have special characters and numbers which the program needs to remove and then reverse the string
0
Thanks XXX
0
Here is a streaming approach that does not retain the whole result. It uses fewer lines of code and fewer variables:
buf = input()
for ch in buf[::-1]:
if (ch.isalpha() or ch==' '):
print(ch, end="")