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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:43:41+00:00 2026-06-14T22:43:41+00:00

I have this dictionary: statuses = { ‘pending’ : {‘status_for’:’all’, ‘position’:1}, ‘cancelled’ : {‘status_for’:’all’,’position’:2},

  • 0

I have this dictionary:

statuses = {
            'pending' : {'status_for':'all', 'position':1},
            'cancelled' : {'status_for':'all','position':2},
            'approved' : {'status_for':'owner', 'position':1},
            'rejected - owner' : {'status_for':'owner', 'position':2},
            'accepted' : {'status_for':'dev', 'position':1},
            'rejected - developer' : {'status_for':'dev', 'position':3},
            'closed' : {'status_for':'dev', 'position':5},
            }

I’ve also got a function to pull all status_for values of either owner or dev that looks like this and put it into a PyQt QComboBox:

for s in statuses:
            if statuses[s]['status_for'] == "dev" or statuses[s]['status_for'] == "all":
                cb_developer_status.addItem(s.capitalize(), s)   

I’d like to order these by the position value though. What is a good way to do this, so that when I populate by combobox I have it in a predefined order?

I realize that the snippet above is checking for both ‘dev’ and ‘all’, my assumption right now is that I’d have to loop through the dictionary twice to get the two separate blocks in the order I wish (ie. ‘all’ appears before ‘dev’).

I saw this post, but I’m not sure how to convert this answer to something that
is a dictionary of dictionaries.

  • 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-14T22:43:42+00:00Added an answer on June 14, 2026 at 10:43 pm

    Would something like this work? Similar to the post you linked, this uses the key function of sorted to provide a custom sort order. iteritems() returns a (key, value) tuple, so that gets passed into lambda (x, y): y['position'], where y['position'] is the value (your nested dictionary, keyed by the status), and position is the item by which you want to sort.

    In [35]: statuses = {
                'pending' : {'status_for':'all', 'position':1},
                'cancelled' : {'status_for':'all','position':2},
                'approved' : {'status_for':'owner', 'position':1},
                'rejected - owner' : {'status_for':'owner', 'position':2},
                'accepted' : {'status_for':'dev', 'position':1},
                'rejected - developer' : {'status_for':'dev', 'position':3},
                'closed' : {'status_for':'dev', 'position':5},
                }
    
    In [44]: for s in sorted(statuses.iteritems(), key=lambda (x, y): y['position']):
       ....:     print s
       ....:
       ....:
    ('accepted', {'position': 1, 'status_for': 'dev'})
    ('approved', {'position': 1, 'status_for': 'owner'})
    ('pending', {'position': 1, 'status_for': 'all'})
    ('rejected - owner', {'position': 2, 'status_for': 'owner'})
    ('cancelled', {'position': 2, 'status_for': 'all'})
    ('rejected - developer', {'position': 3, 'status_for': 'dev'})
    ('closed', {'position': 5, 'status_for': 'dev'})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this CacheManager class which keeps a static dictionary with all sorts of
i have this dictionary: a) 2012 UN NEWNW = ( 2012/06/04 Saudi Arabia Huge
I have this dictionary in my apps model file: TYPE_DICT = ( (1, Shopping
I have this method to get a generic repository out of a dictionary: public
I have a python dictionary of type defaultdict(list) This dictionary is something like this:
I want to have a dictionary of functions. With this dictionary, I could have
I have some data in this form (dictionary): Value0 Text1 Value1 Text2 Value2 Text3
I have a dictionary like this: /// <summary> /// Gets the leave entitlement details.
I have a Dictionary called AvailableBoxes. I want to lookup a string in this
Say that i have a generic dictionary with data like this (I hope the

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.