Commonly occurring words in a file -Assignment

Dear All

Just wanted to share the way I did this. It was different from what @Pratyush sir showed. I also split all the sentences to individual words and stored it as a big list. Then I used the list.count attribute to iterate over this list and count the occurrences of each element of the list. I then initialized a dictionary and assigned the key as the list element and the value as the occurrence (I make sure if the element already existed, I dont add it again in the dictionary)

I then sort the dictionary in the descending order and print the first 10 items

I was glad to note however that @Pratyush sir read my thoughts when I was looking at the stack overflow site when I was googling the sort method and wondering what is this “lambda” keyword :slight_smile:

For the 2 grams, I worked only using “lists”. I did not know about the zip function and so wrote my function to give me the ith and i+1th element by iterating over the list

Once again I used the count attribute of list to count the occurrences of the list items and stored that in a new list. I sorted the list based on the numeric value and printed the 2 grams

Please let me know if you find any fallacy in this approach