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 7841031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:00:36+00:00 2026-06-02T16:00:36+00:00

I have a TDictionary. It’s being filled with an extensive loop. When the loop

  • 0

I have a TDictionary. It’s being filled with an extensive loop. When the loop finishes I need to retrieve the 10 keys(string) with more score(integer). What would be the most efficient way to accomplish this?

In Objective-C(Cocoa) I do it with:

NSArray *top_words_sorted_array = [top_words_dictionary keysSortedByValueUsingSelector:@selector(compare:)];

and then iterating the new sorted array. How can I do it in Delphi?

  • 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-02T16:00:37+00:00Added an answer on June 2, 2026 at 4:00 pm

    The equivalent Delphi code to your Cocoa code is:

    type
      TScorePair = TPair<string,Integer>;
    var
      ScoresArray: TArray<TScorePair>;
    ....
    ScoresArray := Scores.ToArray;
    TArray.Sort(ScoresArray,
      TComparer<TScorePair>.Construct( 
        function(const L, R: TScorePair): Integer
        begin
          Result := R.Value - L.Value;
        end
      )
    );
    

    If your dictionary is very large then this will not be the most efficient solution. On the other hand, it’s probably the quickest and easiest approach to implement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a case using TDictionary: var D: TDictionary<string, integer>; begin D := TDictionary<string,
i have a TDictionary declared like so TDictionary<String,Integer> , Now i want to get
I need a Dictionary<string,object> which is produced from a DataRow. I currently have something
Have Dictionary <Int64, byte> that gets used a lot. I mean in a loop
I have: IDictionary<string, IDictionary<string, IList<long>>> OldDic1; (just for illustration purposes, it is instantiated and
I have dictionary, like Dictionary<string, bool> accValues = new Dictionary<string, bool>() And I want
I have a Dictionary called AvailableBoxes. I want to lookup a string in this
I have code like this: type TMyDictionary = TDictionary<int, int>; var myDict: TMyDictionary; k,
Have this dictionay retrieving values from DataTable: Dictionary<string,string> meta= ds.Tables[1].Select(key<>'format').AsEnumerable().ToDictionary(k=>k.Field<string>(0),v=>v.Field<string>(1)); How would I apply
I have an array of type string that looks like this: test1|True,test2|False,test3|False,test4|True . This

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.