def biggest_family(fil):
with open(fil) as file:
name = {}
ans = {}
text = file.read().split("\n")
for i in range (0 , len(text)-1):
first = text[i].split()
name[first[0]] = first[1]
for b in name:
if name[b] in ans:
ans[name[b]] += 1
else:
ans[name[b]] = 1
print(ans)
The output should be a dictionary of the last name of the family and amount of times it is present in the list. For some reason it works perfectly for some datasets and is short a number on others. As you can see in the picture below it prints the simpsons and griffins in the correct amount but not the Lannister family above it in the first test.