Responsive Ad Area

Share This Post

test

One liner for finding the min value of a subset of a list

I have a method extract_min that takes a list of indices Q and d a list of values.

I want to find the min value in d only for the indices in Q and return the index in Q that has the min value.

The following implemented method works but wondering if there is a one-liner for it.

def extract_min (Q, d):
      R = list(map(lambda x: d[x], Q))
      i = R.index(min(R))
      return Q[i]

For example,

Q = [1, 2, 4]
d = [0, 8, 14, 5, 7]
extract_min(Q, d) = 4


One liner for finding the min value of a subset of a list
One liner for finding the min value of a subset of a list
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar