Hi i am trying to create a function to count the word occurence in a list of text to produce the result as ['a','1'], ['b' ,'4'] , ['c' , '5']......
this is what i tried to do but its not working and i have not learn the count function yet.
file_name = input('what file would you like to open? : ')
objecthere = open(file_name,'r')
argument = objecthere.read()
word_list = argument.split()
def word_frequency(words_from_list, word_frequency):
new_list = []
for word in word_list:
if word in word_list:
new_list.index(word)[1] += 1
else:
new_list.append([word,0])
print(new_list)
Am i on the right track or is there another way?
Edited : Im trying to figure out how do i use the function call in the way that word_frequency(word_list,3) will give me the top 3 word occurence like ['c','3'],['b' , '2'] , ['a' , '1']. Any help or input will be appreciated!