Below you can see a string with a text. Read the number n from the input and print out the n most frequent words from the text with their frequencies. If several words have the same frequency, they should go in the order they appear in the text. The word and the frequency should be separated by whitespace and each word should be on a new line.
E.g. if the text looks like:
text = ("all I want is a proper cup of coffee made in a proper copper coffee pot. "
"I may be off my dot but I want a cup of coffee from a proper coffee pot.")
Then, for the input 1, the output should be a 4, while for the input 2 the output should be:
a 4
coffee 4
You can install any modules if necessary!
Tip: Use the method split() to separate the text into words.