Take the 2-minute tour ×  I have 4 text files that I want to
read and find the top 5 most occurring names of. The text files
have names in the following format "Rasmus,M,11". Below is my
code which right now is able to call all of the text files and
then read them. Right now, this code prints out all of the names
in the files.  def top_male_names ():     for x in range (2008,
2012):         txt = "yob" + str(x) + ".txt"         file_handle
= open(txt, "r", encoding="utf-8")            line =
file_handle.readline().strip()          while line != "":
print (line)             line = file_handle.readline().strip()
My question is, how can I keep track of all of these names, and
find the top 5 that occur the most? The only way I could think
of was creating a variable for each name, but that wouldn't work
because there are 100s of entries in each text file, probably
with 100s of different of names.  share|improve this question
Look into collections.Counter in the standard library. –  Wooble
Nov 25 '13