This program takes an English text as input (case-insensitive) and outputs the top 5 most frequent words along with their occurrence counts.

Input Example:

'From hill to hill no bird in flight;From path to path no man in sight.A lonely fisherman afloat,Is fishing snow in lonely boat.'

Output Example:

[('in', 3), ('from', 2), ('hill', 2), ('to', 2), ('no', 2)]

Another Input Example:

'A green hunting cap squeezed the top of the fleshy balloon of a head. The green earflaps, full of large ears and uncut hair and the fine bristles that grew in the ears themselves, stuck out on either side like turn signals indicating two directions at once. Full, pursed lips protruded beneath the bushy black moustache and, at their corners, sank into little folds filled with disapproval and potato chip crumbs.'

Output Example:

[('the', 5), ('and', 4), ('a', 3), ('of', 3), ('in', 2)]

English Word Frequency Counter: Top 5 Most Frequent Words

原文地址: https://www.cveoy.top/t/topic/oskd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录