Counting on Hackerman’s House

--Originally published at Monty Python and the Blogging Tale

The other day my friend Paco and I were planning to work together, so we saw Ken’s challenge about counting frequency of words; however, at the time we did not know exactly how to start. By the time we decided to do something about it, a girl from the other TC101 (Dani Güemez) had already solved the challenge. But as we read and tested the code, we found a minor flaw: when counting the words in a text file, it separated and counted them by lines instead of counting them all. Here is the orginial code if you want to check it:

https://github.com/Guemez/TC1014/blob/master/countwords.py

Now, the code works fine for counting words in strings; thus, after a little bit of thought, we concluded that the best way to fix that minor error was to make the code convert the files into strings, and then count the words in them. And worked pretty fine. But we went even further and find the way to sort the counter by values. Here is the code:chidori

As you can see, we respected Dani’s format. And here is the final result, with the text we were using:lyrics

We are satisfied with the outcome.

 

This is the link to my friend Paco’s blog: https://firstprogrammingsteps.wordpress.com/

Also be sure to check out Dani’s blog: https://danigguemez.wordpress.com/