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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:02:10+00:00 2026-06-07T17:02:10+00:00

I have one question about writing a code on dictionaries i have done the

  • 0

I have one question about writing a code on dictionaries i have done the coding but i am confused on one part this is what it says the parameter name is sort_by_value: “(dict of {immutable_type:int}) -> list” and the description is “Return a list of keys in the dictionary sorted in ascending order according to their values. Keys with identical values might be sorted in any order. “

and my code that i wrote is

    def sort_by_value(dict):
        """
        (dict of {immutable_type:int}) -> list   """
        L = []
        for x in dict.values():
            L.append(x)
        L.sort()
        print L

this code ascends it with the value only like say if I had a dictionary

    nd = {} 
    nd['john'] = 109090 
    nd['albert'] = 1900 
    nd['Tim'] = 18000 
    sort_by_value(nd)

I get the list [1900, 18000, 109090] but I need to get the keys associated with those values like I want [‘albert’, ‘Tim’, ‘john’]

I did try giving it a try and tried to introduce another for loop
right before Print L I wanted to write

   keyList= []

    for x in L:
        keyList.append(dict.get())
        if 

but i dont know if that would work please need of helppp

  • 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-07T17:02:13+00:00Added an answer on June 7, 2026 at 5:02 pm

    You can use built-in sorted function to sort tuple of that dictionary.

    nd = {}
    nd['john'] = 109090
    nd['albert'] = 1900
    nd['Tim'] = 18000
    
    print sorted(nd.items(), key=lambda x: x[1])
    

    Which will return:

    [('albert', 1900), ('Tim', 18000), ('john', 109090)]
    

    if you want to get keys only:

    print map(lambda x: x[0], sorted(nd.items(), key=lambda x: x[1]))
    

    will give you:

    ['albert', 'Tim', 'john']
    

    Refer: http://wiki.python.org/moin/HowTo/Sorting/

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

Sidebar

Related Questions

I have one question about writing a dictionary given a file. I have done
I'm a bit confused on url writing in .htaccess and have a question about
After writing a sample code for the question about converting between timezones , one
i have one question about jquery ajax().. I created a table grid and there
I have one question about searching and counting files in directories and subdirectories. I
I have one question about Yii framework, and I need your help. Basicly, I
Ok, i have one totaly noob question about php sessions: I have 3 (and
I have a question about Criteria method, one-to-many relation to the database, 'one' is
This is a question about coding style and recommended practices: As explained in the
I am writing a script in Perl and have a question about Perl's foreach

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.