I’m using the following code to split array of strings into list.
private List<string> GenerateTerms(string[] docs)
{
return docs.SelectMany(doc => ProcessDocument(doc)).Distinct().ToList();
}
private IEnumerable<string> ProcessDocument(string doc)
{
return doc.Split(' ')
.GroupBy(word => word)
.OrderByDescending(g => g.Count())
.Select(g => g.Key)
.Take(1000);
}
What I want to do is replace the list returned with
Dictionary <string, int>
i.e. instead of returned list , i want to return Dictionary
Could anyone help ?? thanks in advance.
EDIT:
I believe you are looking to get a final dictionary from array of strings, based on words as key and their final count as values. Since dictionary can’t contain duplicate values, so you will not be required to use
Distict.You have to re-write your methods as:
Then you can call it like: