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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:59:38+00:00 2026-06-05T12:59:38+00:00

So I have a multi-dimensional dictionary that has a numeric key identifying an inner

  • 0

So I have a multi-dimensional dictionary that has a numeric key identifying an inner dictionary, but the inner dictionary does not have numeric keys. I’m having difficulty creating a sorted list of keys based on the value of one of the inner dictionary’s string indices. I might not have described the issue properly, so here is an example script highlighting the issue:

#! /usr/bin/python
my_dict = {
        12608: {
                'market_data':  {
                    'sellVolume': 69210, 'buyValue': 296.20999999999998,  
                    'sellValue': 523.20000000000005, 'buyVolume': 9210899
                    }
            },
        24513: {
            'market_data': {
                'sellVolume': 42148, 'buyValue': 548.95000000000005,  
                 'sellValue': 890.0, 'buyVolume': 11213386
                }
            },
        12773:  {
                'market_data': {
                    'sellVolume': 383000, 'buyValue': 609.54999999999995, 
                    'sellValue': 799.98000000000002, 'buyVolume': 10285288
                    }
            },
        24486: {
            'market_data': {
                'sellVolume': 1314250, 'buyValue': 99.780000000000001,  
                'sellValue': 425.0, 'buyVolume': 14690060
                }
            },
        2801: {
            'market_data': {
                'sellVolume': 247577, 'buyValue': 348.98000000000002, 
                'sellValue': 518.94000000000005, 'buyVolume': 10325916
                }
            }
    }

d_sorted = sorted(my_dict, key=lambda \
       x: my_dict[x]['market_data']['buyValue'], reverse=True)

print "key\tbuyValue"
for key in d_sorted:
    print "%d\t%.2f" % (key, my_dict[key]['market_data']['sellValue'])

And here are the results of the script

# Results:
# key         buyValue
# 12773   799.98
# 24513   890.00
# 2801    518.94
# 12608   523.20
# 24486   425.00

# Expected:
# key         buyValue
# 24513   890
# 12773   799.98
# 12608   523.2
# 2801     518.94
# 24486   425

The example dictionary is not my full use-case, but a stripped down version to show the problem (there’s another inner-dictionary that was unimportant to the issue for example). I mention this because there might be a better data type to use than dictionary that I’m unaware of, being new to python.

The question here was instrumental in getting me this far, and the main difference I see is that my second dimension does not use integer keys.

I’m using python version 2.6.7, if it matters.

  • 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-05T12:59:39+00:00Added an answer on June 5, 2026 at 12:59 pm

    As I said in the comment below the question, your table header says “BuyValue” and you are printing “Sell value”. Going by the output what you expect, I think you just made a small mistake in setting the sorter function.

    It should be:

    lambda x: my_dict[x]['market_data']['sellValue']
    

    and not

    lambda x: my_dict[x]['market_data']['buyValue']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi dimensional array with 200 keys and each key has 3
I'm having a problem lately that's driving me crazy. I have a multi-dimensional array
I have an multi-dimensional array that I want to send to a PHP script
I have a multi-dimensional array right now that looks like this: function art_appreciation_feeds() {
I have a multi-dimensional array that I'd like to use for building an xml
I have this combination of multi-dimensional array but I can't print the correct value
I have a JSON file that I would like to create an multi-dimensional array
Say you have the following ANSI C code that initializes a multi-dimensional array :
I have a very specific problem here. I have a multi-dimensional array that I
I have a multi-dimensional array called my_ids_and_names It should probably be a hash but

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.