The end of the semester is near, and we are seeing more advanced codes that in the beggining of the semester. This WSQ was kind of cool for me, since I enjoyed using the open files as read and writting. I do not know why, but do not judge me.
For testing purposes, the text used for this WSQ says the following:
ThisThis This is a test for wsq012 in order to count the words in this file
I used two methods for this WSQ. The first one was with a line.split() while reading the document. This way the program separates and reads the document line by line. Then search the word in the document with a conditional if. Then it adds the total matches to the counter.
As you may notice, this method does not distinguishes the matches of the established word if this word is mixed between the text without any space to separate it. For example, “This” is the word to search. Text says “Thisthis” that are two matches, tecnically; however, the code only recognizes it as one.
This is why I made the second version of the WSQ. Ken suggested to use find() in order to avoid this problem; however, since I failed in using it correctly, I rather used count(). By the way, I also improved the code by using .lower(), so it does not matters if the text and words are submited in cappital letters.
What is this? A picture for ants? Well… you can take a closer look at the code in my GitHub!
Now that this blog has finally reach it’s end. Let me introduce you to Cage the Elephant and their song called “Ain’t No Rest for the Wicked”. Released
2013, this song was used for the intro of Borderlands, the first game from the epic saga. This song shows us that there is never a moment of one’s life where one does not have to make an effort.
WSQ12 ‘Word Count’ by rhcpalmarichie is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.