Program 13: Take a sample of 10 phishing e-mails and find the most common words

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

# Python program to find the k most frequent words 
# from data set 
from collections import Counter 

#data_set = "phished emails"  
def most_common_word(dataset , n=10):   
    # split() returns list of all the words in the string 
    split_it = data_set.split() 
    
    # Pass the split_it list to instance of Counter class. 
    count = Counter(split_it) 
    
    # most_common() produces k frequently encountered 
    # input values and their respective counts. 
    most_occur = count.most_common(n) 
    
    print(most_occur)

You cannot copy content of this page