protected IList <IList <string> > GetGroupedAnagrams() { var lastValue = string.Empty; var groupedAnagrams = new List <IList <string> >(); IList <string> tempAnagramsList = new List <string>(); foreach (var word in indexedInput.GetSortedList()) { if (!lastValue.Equals(word.Value) && !lastValue.Equals(string.Empty)) { groupedAnagrams.Add(tempAnagramsList); tempAnagramsList = new List <string>(); } tempAnagramsList.Add(indexedInput.GetUnmodifiedList()[word.Key]); lastValue = word.Value; } if (tempAnagramsList.Count > 1) { groupedAnagrams.Add(tempAnagramsList); } return(groupedAnagrams); }