How to find the item in a list whose f(item) is the smallest? I have a list, l and a function f. f is not strictly increasing or decreasing. How can I find the item in the list whose f(item) is the smallest? For example, let's say the list is:

l = [1, 2, 3, 4]


and list(f(x)for x in l) is:

[2, 9, 0, 3]


f(3) is smaller than f of any of the other ones, so it should print "3". What's the shortest way to do this? I initially tried:

min(f(x) for x in l)


But this gives 0, not 3. If I was shooting for readability, not brevity, I would do:

index = 0
smallest = f(l[0])
for i in range(len(l)):
    value = f(l[i])
    if value &lt; smallest:
        smallest = value
        index = i


This is fine, but horrendous for code-golf. Even if it was golfed

i,s=0,f(l[0])
for x in range(len(l)):
 v=f(l[x])
 if v&lt;s:s,i=v,x


This is a bad solution. The shortest solution I can think of is:

g=[f(x)for x in l];print(l[g.index(min(g))])


(44 bytes) How can I golf this down further?
Use key property of min

As @vaultah said, use min(l,key=f). min(l,key=f) takes the minimum of f(i) for i in l.

It is also possible to apply this to max, and sorted. For example, max(l,key=f) is the maximum of f(i) for i in l. For sorted, the usage would be: sorted(l,key=f).