![](/img/trans.png)
[英]Count the number of unique words and occurrence of each word from txt file
[英]Show top {n} words by occurrence and include count
制作一個子功能用於在討論區中顯示最常用的唯一單詞的應用程序(諸如“ the”和“ and”之類的非有用單詞已被過濾掉)
他們要求列出使用的前10個單詞以及它們出現的百分比。 我可以考慮百分比,但是我不確定采用單個字符串(例如10,000個單詞)並顯示排名前10位的事件以及排名前10位的事件發生次數的最有效方法。
var listOfWords = GetMyListOfTenThousandWords();
listOfWords.GroupBy(
low => low,
// Return an anonymous object with the word and it's count
(key, result) => new { Word = key, Count = result.Count() }
).OrderByDescending(w => w.Count)
.Take(10);
我對的重載2快速書面記錄GroupBy
在這里 ,如果你想了解更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.