From the course: Python for Non-Programmers
Unlock the full course today
Join today to access over 25,200 courses taught by industry experts.
Counting the words - Python Tutorial
From the course: Python for Non-Programmers
Counting the words
- [Instructor] Currently our word counter can tell us how many words there are in a particular piece of text, but it doesn't tell us how many times a particular word appears. So for us working on this next part of our code, I think it will help if we really simplify the text that we're looking at. So just temporarily, I'm going to get rid of the speech and just bring in some letters. So I'm going to have a, b, c, a, a, and then also b. So that we have a few letters that are repeating. So just to make sure this is working, let's go ahead and run this. Says that we have six words, and if we get rid of the length here to say just show me what we have, we can see, okay, I've got a list of a, b, c, a, a, b. So now, if we want to count these, the question is, how do we do that? Well, a great way to go about this is to use a dictionary because with a dictionary, we could store the words or in this case, these letters as the…