infile = open("birds.txt",'r') birds = {} for line in infile: # Get rid of the \n at the end name = line.strip() if not name in birds: birds[name] = 1 else: birds[name] += 1 for b in birds: print(b,birds[b]) infile.close()