Search code examples
pythonzipmin

How to get all the minima in a tuple?


I have a two variable, a = ("0", "2", "0") b = ("Jenny", "Christy", "Monica") if I run the code

x = min(zip(a, b))
print(x)

my output will be ('0', 'Jenny')

If I want the output- (('0', 'Jenny'),('0','Monica))- what should I do?


Solution

  • In fact, you want the min of a:

    >>> [(i, j) for i, j in zip(a, b) if i == min(a)]
    [('0', 'Jenny'), ('0', 'Monica')]
    

    If you compare each tuple then ('0', 'Jenny') < ('0', 'Monica')