I am wanting to return the number of times certain letters are used to begin words in a .txt file. For instance, "stop talking tim" would have a s = 1 and t = 2 for the first character counts. How could I go about doing this?
Asked
Active
Viewed 25 times
0
-
1Have you tried anything yet? If you have, please show your code. Explain what is not working out for you. – idjaw Mar 07 '16 at 18:13
-
Edit your question and put that code in there and format it properly, please. – idjaw Mar 07 '16 at 18:28
1 Answers
1
Just to get you started, we were all beginners once:
from collections import Counter
s = "stop talking tim"
words = s.split()
letters = [w[0] for w in words]
print Counter(letters)
Gives:
Counter({'t': 2, 's': 1})

daedalus
- 10,873
- 5
- 50
- 71