+ 2
How to use the .isalpha() or a similar method here?
I'm trying to find a way to return only the letters of an input string, but my code is returning the (' ') count as well, I don't want that, I know that there is a method .isalpha() that only returns letters as far as I know, however I'm not sure to make it work here, thanks in advance https://code.sololearn.com/chv9Lb361CAr/?ref=app
15 Answers
+ 3
Whally O just return the dictionary named "result" instead of "string". You're all done ๐๐ป๐๐ป
+ 2
๐๐ข๐ข๐๐จ ๐๐ก๐๐ฒ๐๐ฅ is there right now, I modified the var:
text=text.replace(" ", "")
as you taught me
+ 2
Code Crasher great! Thank you very much, don't get me wrong, any assistance or help is more than welcome!, and now I can a find a way with a while loop because of you
+ 2
Mirielle [INACTIVE] your answer is good but for beginners it may be hard to understand. So you should give easy answer(edit: code) so that the person who is asking can understand it and use that logic..
+ 2
Mirielle [INACTIVE] ok sorry for 'answer' instead of 'code'. I am talking about the code('one line' for beginner is not good habit)
But why to use ASCII if python alreday has "isalpha" method.
+ 2
Dictionary comprehension to try out
def count_comp(words):
words = words.lower()
return {word:words.count(word)
for word in words.replace(" ","")}
+ 1
๐๐ข๐ข๐๐จ ๐๐ก๐๐ฒ๐๐ฅ
Are you using the parameter (t) as test?
In your first example is not necessary to indent after the for loop?
Sorry, but is showing me error on the first and third example, I'll try with the second.
+ 1
๐๐ข๐ข๐๐จ ๐๐ก๐๐ฒ๐๐ฅ
Yes, they are working, I'm trying to work with the third one, but is returning some other characters like '=', '+'
+ 1
Code Crasher
Thanks, the thing is that the for loop is part of the problem steps, built-in
+ 1
Mirielle [INACTIVE]
Thank you! Now I can try a way with "lambda" as well
+ 1
๐๐ข๐ข๐๐จ ๐๐ก๐๐ฒ๐๐ฅ
What's up? I hope everything is fine with you, not only spaces, basically they only want the keys to return a count of the values of letters only, sorry if I sound repetitive, I'm also trying to find different ways with the problem requirements, that website that you mentioned is amazing, I use their knowledge and resources sometimes
+ 1
Whally O check this..
(I think it can solve your problem..)
edit: improved printing of number of letters..
https://code.sololearn.com/cWTJFnh2V98p/?ref=app
+ 1
AKSHAY
Thank you! Now I see that is printing only letters in your code, sorry but, one question, how to return the result in a dictionary where keys are the letters and values are the count of the different letters on the input strings, please?
+ 1
AKSHAY
Like the voice says in Mortal Kombat: "Outstanding!", that's exactly what the problem was asking us to do, thank you!
- 1
Bx