I create a program that reads through the .txt file of names (lastname, firstname), one per line and creates a dictionary that shows the number of repetitions of a particular name.
I have received the following code so far, but I canβt accurately count the number of repetitions of the name. I think the problem is that my variable βvalueβ does not match the actual value in the key value pair. How can i fix this?
file = open('names.txt') dict = {} value = 1 for line in file: listOfNames = line.split(",") firstName = listOfNames[1] if dict.has_key(firstName): value += 1 else: dict[firstName] = value file.close()
user1063450
source share