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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:16:03+00:00 2026-05-29T15:16:03+00:00

I am referring to the question: https://stackoverflow.com/a/575889/292291 If I use integers as the key,

  • 0

I am referring to the question: https://stackoverflow.com/a/575889/292291

  1. If I use integers as the key, it appears I am guaranteed a sorted order?

    >>> dict = { 2: "list 2", 0: "list 0", 1: "list 1" }
    >>> dict
    {0: 'list 0', 1: 'list 1', 2: 'list 2'}
    
  2. In sorted(mydict, key=lambda key: mydict[key]), how do I interpret or read the lambda? I don’t understand that part since I’m new to lambdas. What does key: and mydict[key] refer to?

  3. In sorted(d, key=d.get) what does d.get refer to? If I do:

    >>> dict.get
    <built-in method get of dict object at 0x1d27830>
    
  • 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-29T15:16:04+00:00Added an answer on May 29, 2026 at 3:16 pm

    1- Dicts never guarantee an order, sometimes it may even look like it does, but get enough numbers in there and you’ll see they don’t (this is because of the way that hashes are obtained for each key)

    2- These two are the same:

    lambda key: mydict[key]
    
    def temp_function(key):
        return mydict[key]
    

    Basically, you are creating a temporary function that receives key as a parameter, and returns mydict[key]

    3- The second argument of sorted refers to the function that will be called, passing the current dict key. The value returned by this will be used to determine the order of your sorted dict.

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

Sidebar

Related Questions

Referring to this question: https://stackoverflow.com/questions/2035449/why-is-oop-hard-for-me class Form { protected $inputs = array(); public function
Referring to this question , how can i get the current page size in
referring to this question , I've decided to duplicate the tables every year, creating
Referring to TLB and maintenance issues ... My question to people (often) using the
My co-worker posted a question on his blog . He is referring to rendering
i am referring to answer to my question , answer was provided by @abhy,
I have a .htaccess related question. For example, if I have two domain, a.com
Referring on this question , I have a similar -but not the same- problem..
This is referring to the question i asked before, and got a really quick
To begin with, let me apologise for asking yet another question referring this topic.

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.