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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:01:56+00:00 2026-06-19T03:01:56+00:00

I was reading the question where the desired output was to get the element

  • 0

I was reading the question where the desired output was to get the element with minimum value

so if

d= {'a':2,'b':3,'f':5}

The answer is a

The answer given is min(d, key=d.get)

can anyone explain how this works

  • 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-19T03:01:57+00:00Added an answer on June 19, 2026 at 3:01 am

    The min function returns the minimum value of an iterable according to the given key. In this case it returns the key of d with the minimum value. d.get allows you to access the corresponding value to the dictionary key, which are iterated over when you iterate over d.

    For example:

    >>> min([3, 5, 2, 1, 5])
    1
    >>> d = {'a': 1, 'b': 2, 'c': 3}
    >>> for i in d:
    ...     print i
    b
    c
    a
    >>> d.get('b')
    2
    >>> d.get('d')  # Nothing is returned
    >>> min(d, key=d.get)
    'a'
    

    The key argument to the min specifies what key you want to find the minimum on.

    For example:

    >>> min(['243', '172344', '6'])
    172344
    >>> min(['243', '172344', '6'], key=len)
    6
    

    The min function does something like this:

    >>> min(['243', '172344', '6'], key=len)
    # sort the list with key (call `len` on every element and sort based on that)
    # sorted(['243', '172344', '6'], key=len)
    # return the first element (lowest value)
    # sorted(['243', '172344', '6'], key=len)[0]
    6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading this question got me thinking: For a given function f , how can
After reading this question , i saw the answer by Naveen containing a link
I was reading this question, but didn't understand some part of the aix's answer
In response to my answer to a file-reading question , a commenter stated that
I've spent all day reading tutorials but can't seem to find an answer to
After reading through various tutorials [1] I still can't get my VirtualHost settings to
After reading this question, I need to clear up some things. IQueryable<Customer> custs =
I was reading this question (which you do not have to read because I
I was reading another question pertaining the efficiency of two lines of code, and
Check this example before reading the question - http://www.sqlfiddle.com/#!2/fcf3e/8 The following data comes from

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.