+ 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

11th Jul 2020, 3:55 AM
Whally O.
Whally O. - avatar
24 Answers
+ 3
Whally O just return the dictionary named "result" instead of "string". You're all done ๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป
13th Jul 2020, 3:42 AM
AKSHAY๐Ÿ‡ฎ๐Ÿ‡ณ
AKSHAY๐Ÿ‡ฎ๐Ÿ‡ณ - avatar
+ 2
๐Š๐ข๐ข๐›๐จ ๐†๐ก๐š๐ฒ๐š๐ฅ is there right now, I modified the var: text=text.replace(" ", "") as you taught me
11th Jul 2020, 5:00 AM
Whally O.
Whally O. - avatar
+ 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
11th Jul 2020, 6:50 AM
Whally O.
Whally O. - avatar
+ 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..
12th Jul 2020, 9:26 AM
AKSHAY๐Ÿ‡ฎ๐Ÿ‡ณ
AKSHAY๐Ÿ‡ฎ๐Ÿ‡ณ - avatar
+ 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.
12th Jul 2020, 1:34 PM
AKSHAY๐Ÿ‡ฎ๐Ÿ‡ณ
AKSHAY๐Ÿ‡ฎ๐Ÿ‡ณ - avatar
+ 2
Dictionary comprehension to try out def count_comp(words): words = words.lower() return {word:words.count(word) for word in words.replace(" ","")}
13th Jul 2020, 7:29 AM
Den
Den - avatar
+ 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.
11th Jul 2020, 4:24 AM
Whally O.
Whally O. - avatar
+ 1
๐Š๐ข๐ข๐›๐จ ๐†๐ก๐š๐ฒ๐š๐ฅ Yes, they are working, I'm trying to work with the third one, but is returning some other characters like '=', '+'
11th Jul 2020, 4:42 AM
Whally O.
Whally O. - avatar
+ 1
Code Crasher Thanks, the thing is that the for loop is part of the problem steps, built-in
11th Jul 2020, 5:11 AM
Whally O.
Whally O. - avatar
+ 1
Mirielle [INACTIVE] Thank you! Now I can try a way with "lambda" as well
11th Jul 2020, 9:56 PM
Whally O.
Whally O. - avatar
+ 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
11th Jul 2020, 10:09 PM
Whally O.
Whally O. - avatar
+ 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
12th Jul 2020, 9:14 AM
AKSHAY๐Ÿ‡ฎ๐Ÿ‡ณ
AKSHAY๐Ÿ‡ฎ๐Ÿ‡ณ - avatar
+ 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?
12th Jul 2020, 5:47 PM
Whally O.
Whally O. - avatar
+ 1
AKSHAY Like the voice says in Mortal Kombat: "Outstanding!", that's exactly what the problem was asking us to do, thank you!
13th Jul 2020, 4:46 AM
Whally O.
Whally O. - avatar
- 1
Bx
12th Jul 2020, 12:19 PM
Sonu Raj
Sonu Raj - avatar