Search code examples
pythonzip

Finding the minimum value after using zip


Good day! I'm trying to learn about the zip() function. I combined two lists using zip.

a = [1,3,5,7]
b = [40,30,20,10]

c = list(zip(a,b))

print(c)

This is the output:

[(1, 40), (3, 30), (5, 20), (7, 10)]

I want to access the element of the zip function if the second column is minimum. For example, the minimum value for the 2nd column is 10. If I use the zip function and get 10, I'm expecting an answer of

(7,10)

I tried something like this:

for i,j in c:
    if c[i][j] == min([c[j]):
        print(c)

I end up with an error and don't know what to do. Thank you for your help!


Solution

  • You're probably looking for something like this:

    minimum = min(map(lambda elem: elem[1], c))
    
    for elem in c:
        if elem[1] == minimum:
            print(elem)