Skip to content

Instantly share code, notes, and snippets.

@droyad
Created September 18, 2013 09:37
Show Gist options
  • Select an option

  • Save droyad/6606825 to your computer and use it in GitHub Desktop.

Select an option

Save droyad/6606825 to your computer and use it in GitHub Desktop.
var all = @"// redacted";
var firstLetters = all
.Split('\n')
.Select(n => n.Trim().ToUpper())
.Select(n => n.Substring(n.IndexOf(" ") + 1)[0]);
var counts = from l in firstLetters
group l by l into g
select new
{
Letter = g.Key,
Count = g.Count()
};
var forAll = from a in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
join l in counts on a equals l.Letter into j
from x in j.DefaultIfEmpty()
orderby a
select new
{
Letter = a,
Count = x == null ? 0 : x.Count
};
forAll.Dump();
forAll.Sum(x=> x.Count).Dump();
forAll.Where(x => x.Letter <= 'P').Sum(x=> x.Count).Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment