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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:04:55+00:00 2026-05-26T17:04:55+00:00

I have a dictionary with id and multiple values for each ID which are

  • 0

I have a dictionary with id and multiple values for each ID which are strings. For each value in that for each Id I make a database query and get set results:

{111: Run, Jump, swim}
{222: Eat, drink}

so for each value lets say run I execute a query and it returns another set of data then pick each value of that set and run query which will give another set and finally I come to a point where there is only one item get return. Once I finish get that final element of every single sub element of Run then I move to Jump and continue.

I asked this question before but didn’t get any results so people told me to remove the code and just ask the question again. Here is the link for the same question which I ask few days ago. Do i need to implement something like disjoin set?

  • 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-05-26T17:04:55+00:00Added an answer on May 26, 2026 at 5:04 pm

    You can look at the categories/subcategories as a tree with N branches at each node (depending how many categories you have). From what I can gather you basically want to generate an in-order list of tree leaves.

    One simple way of doing it is through generators (using the terminology from your original question):

    def lookup(elem):
        # do your SQL call here for a given category 'elem' and return
        # a list of it's subcategories
        return []
    
    def leaves(lst):
        if lst:
            for elem in lst:                          # for every category
                for sublist in leaves(lookup(elem)):  # enumerate it's sub categories
                    yield sublist                     # and return it
                yield elem                            # once lookup(elem) is [] return elem
    
    d = { 111: [Run, Jump, swim] , 222: [Eat, drink] }
    
    for key, lst in d.items():
        print key, [elem for elem in leaves(lst)]
    

    If you are unfamiliar with generators, they are simply iterator constructs that “yield” values instead of returning them. The difference is that yielding only pauses the iterator at that location which will continue where it stopped when the next value is requested.

    With some clever recursion inside the generator you can simply parse the whole tree.

    The [elem for elem in leaves(lst)] is a list comprehension and it simply builds a list containing elem for every element iterated by leaves.

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

Sidebar

Related Questions

I have a Dictionary that when I add multiple values to it, the items
I have a dictionary where each keys have multiple values. I am trying to
I have the following code which produces a dictionary containing multiple lists; each list
I have a dictionary of 200,000 items (the keys are strings and the values
I have a dictionary where keys are strings, and values are integers. stats =
Is accessing/changing dictionary values thread-safe? I have a global dictionary foo and multiple threads
I have the following code copy/pasted multiple times. The values that change are the
I have a dictionary structure, with multiple key value pairs inside. myDict.Add(key1, value1); myDict.Add(key2,
I have multiple threads who all need to write to the same Dictionary. I
Does VBA have dictionary structure? Like key<>value array?

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.