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

  • Home
  • SEARCH
  • 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 8578441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:23:23+00:00 2026-06-11T20:23:23+00:00

I have a main dictionary like this: data = [{key1: value1, key2: value2, key3:

  • 0

I have a main dictionary like this:

data = [{"key1": "value1", "key2": "value2", "key3": "value3"}, {"key1": "value1", "key2": "value5", "key3": "value6"}, {"key1": "value2", "key2": "value2", "key3": "value9"} ]

And i need to create a dictionary out of it assuming there is a unique combination of [value for "key1"] and [value for "key2"]:

i.e., i need to create a dictionary like:

result = [{"value1" {"value2" : "value3", "value5" : "value6"}}, {"value2" {"value2" : "value9"}}]
  • 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-11T20:23:24+00:00Added an answer on June 11, 2026 at 8:23 pm

    I’m not sure I understand exactly what you are looking for but here is a little program that will do something close to what you are describing. Please note that this question has nothing to do with any of the tags you have marked it with. It’s a basic algorithmic problem.

    int main (int argc, const char * argv[]) {
    
        @autoreleasepool {
    
            NSArray *array = @[
                @{@"key1": @"value1", @"key2": @"value2", @"key3": @"value3"},
                @{@"key1": @"value1", @"key2": @"value5", @"key3": @"value6"},
                @{@"key1": @"value2", @"key2": @"value2", @"key3": @"value9"}
            ];
    
            NSMutableDictionary *result = [NSMutableDictionary dictionary];
    
            for (NSDictionary *dict in array) {
                [dict enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
                    NSMutableArray *valuesForKey = [result objectForKey:key];
                    if (valuesForKey == nil) {
                        valuesForKey = [NSMutableArray array];
                        [result setObject:valuesForKey forKey:key];
                    }
                    [valuesForKey addObject:value];
                }];
            }
    
            for (id key in result.allKeys) {
                NSMutableArray *valuesForKey = [result objectForKey:key];
                [valuesForKey sortUsingSelector:@selector(compare:)];
            }
    
            NSLog(@"Dictionary: %@", result);
        }
        return 0;
    }
    

    The output is the following:

    2012-09-24 20:44:02.509 Dummy[68684:303] Dictionary: {
        key1 =     (
            value1,
            value1,
            value2
        );
        key2 =     (
            value2,
            value2,
            value5
        );
        key3 =     (
            value3,
            value6,
            value9
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Class structure like this: class A { Dictionary<UInt64, B> listB; method1(){}
I have a list of dictionaries like this: data = [{'x': 1, 'y': 10},
I have a dictionary that goes like this: typedef struct dictNode { int key;
I Have a Challenge like this, Dictionary<string,Dictionary<string,int>> dic=new Dictionary<string,Dictionary<string,int>>(); i want them into a
I have a dictionary of data, the key is the file name and the
I have a list of dictionaries like in this example: listofdict = [{'name': 'Foo',
I currently have a menu with subitems that is being stored in this dictionary
I have a main data store which has a big set of perfectly ordinary
I have a function like this: private void GetRSS(int start, int end) { for
I'm trying to make a multi-lingual dictionary with one main language. I would like

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.