Created
December 27, 2021 05:22
-
-
Save taylorhutchison/4ea1031ac18a260b33c94fb077892cc5 to your computer and use it in GitHub Desktop.
Output the distribution of English words by their first letter (ignoring case).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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