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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The
minfunction returns the minimum value of an iterable according to the given key. In this case it returns the key ofdwith the minimum value.d.getallows you to access the corresponding value to the dictionary key, which are iterated over when you iterate overd.For example:
The
keyargument to theminspecifies what key you want to find the minimum on.For example:
The
minfunction does something like this: