Find The Most Frequent Words That Appear In The Dataset
I write a function that takes as input a list and returns the most common item in the list. ##Write the function def most_frequent(List): dict = {} count, itm = 0, ''
Solution 1:
It's return itm
(most common item) instead of return item
(last part of your reversed list)
Solution 2:
It seems as though you might be using the wrong filename for the restauarant names file. Judging from your curl command:
!curl https://raw.githubusercontent.com/ipeirotis/introduction-to-python/master/data/restaurant-names.txt -o restaurant-names.txt
The filename you should be using is restaurant-names.txt
so your code should be:
# create the list from the restaurants.txtList = open("restaurants-names.txt").readlines()
# get the most most frequent restaurant namesprint("The most frequent restaurant names is ",most_frequent(List))
Solution 3:
It might be the function that is wrong, what if you try the same test data but in a different order, for example: list = [42,5,34,6,5,7,4,2]
instead of list = [5,42,34,6,7,4,2,5]
, is the output still 5?
Post a Comment for "Find The Most Frequent Words That Appear In The Dataset"