Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:01:07+00:00 2026-06-14T19:01:07+00:00

I have a dictionary that stores strings as keys and ints as values that

  • 0

I have a dictionary that stores strings as keys and ints as values that represent words and the number of times they occur. The user needs to be able to sort them by number of uses or alphabetically by 1st letter. I’d prefer to use LINQ although I am rather new to it. I have been able to group the words based on starting letter using the following code:

public string AlphabeticWordBuilder()
{
    List<String> words = this.myWords.WordsAsList();
    words.Sort();
    return GroupWords(words);
}

private static string GroupWords(List<String> words)
{
    String formatedWords = string.Empty;
    var groups =
        from w in words
        group w by w.First();
    foreach (var group in groups)
    {
        formatedWords += ("\n" + group.Key + ":\n");
        foreach (var w in group)
        {
            formatedWords += (w);
        }
    }
    return formatedWords;
}

However this method requires me to convert the keys of my dictionary into a list causing me to lose my values. I should be able to group my dictionary by the value in a similar fashion but I do not know how to incorporate the key/value relationship into the code I am using for the alphabetic sorting. Can someone please post an example of using LINQ to group a dictionary by value?

Also I’d like to avoid the LINQ method syntax and continue to use the LINQ query expression syntax shown above if possible.

Example output alphabetically:

Words starting with a:

and adventure a an (ect.)

Example output by frequency:

Words occurring 1 time(s):

stuff and problems

An incomplete example of what I’m trying to do:

public string FrecquincyWordBuilder()
{
    string fromatedWords = string.Empty;
    var groups =
        from w in this.myWords
        group w by w.value;
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:01:08+00:00Added an answer on June 14, 2026 at 7:01 pm

    This is the code I am using.

      public string FrecquincyWordBuilder()
      {
    
          string fromatedWords = string.Empty;
          this.myWords.SortByFrequency();
          Dictionary<string, int> wordsAndFec = this.myWords.wordsAsDictionary();
          return GroupWordsByFercs(wordsAndFec);
    
    
      }
    
      private static string GroupWordsByFercs(Dictionary<string, int> wordsAndFec)
      {
          String formatedWords = string.Empty;
          var groups =
              from w in wordsAndFec
              group w by w.Value;
          foreach (var group in groups)
          {
              formatedWords += ("\n Words ocurring " + group.Key + " times:\n");
              foreach (var w in group)
              {
                  formatedWords += (w.Key + " ");
              }
          }
          return formatedWords;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary of strings that i want the user to be able
I have a dictionary whose keys are strings and values are numpy arrays, e.g.:
I have a dictionary collection that stores the starting position and the charecter values
I have a dictionary that has keys associated with lists. mydict = {'fruits': ['banana',
I have a dictionary structure that maps an id (integer) into a number (double).
I have a class that stores a list of dictionary entries. I want bind
I have an application that manages a large number of strings. Strings are in
I have data in a python dictionary that I'd like to store in a
If I have, say, 100 items that'll be stored in a dictionary, should I
I have a dictionary that hosts diameter(in mm) and worth of euro coins: CoinsDiameters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.