The new programmer is here. At the moment I have a dictionary for my program, containing all the years and how many complete words were used in the literature for each year.
Now I need to find the relative frequency this year by looking at a specific word given by the user. The relative frequency is determined by using the number of times a particular word was used, and dividing it by the total number of words that were used during that year.
Do I need to make another dictionary containing the year and the number of times the word was used in this year? Or another data structure completely? It should also be mentioned that the user provides a start and end date.
Below is my function for the dictionary that I have. If you have suggestions on how to make this better, I’m all ears!
yearTotal = dict() def addTotal(): with open('total_counts.csv') as allWords: readW = csv.reader(allWords, delimiter=',') for row in readW: yearTotal[row[0]] = row[1] addTotal()
source share