Skip to content

Instantly share code, notes, and snippets.

@taylorhutchison
Created December 27, 2021 05:22
Show Gist options
  • Save taylorhutchison/4ea1031ac18a260b33c94fb077892cc5 to your computer and use it in GitHub Desktop.
Save taylorhutchison/4ea1031ac18a260b33c94fb077892cc5 to your computer and use it in GitHub Desktop.
Output the distribution of English words by their first letter (ignoring case).
// Steps to reproduce assuming you have dotnet installed (using version 6).
// mkdir english-word-distribution && cd english-word-distribution
// dotnet new console
// curl https://raw.githubusercontent.com/dwyl/english-words/master/words.txt --output words.txt
// dotnet run
var letterCount = new Dictionary<char, int>();
foreach (var word in File.ReadLines("words.txt"))
{
var letter = word.ToLower()[0];
if (!letterCount.ContainsKey(letter))
{
letterCount[letter] = 0;
}
letterCount[letter]++;
}
foreach (var letter in letterCount.OrderBy(lc => lc.Key))
{
Console.WriteLine($"{letter.Key},{letter.Value}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment