I posted I need the min of the first element and max of the second, should have added that is in the same pair. In the list [0,36], 0 is min of the first element and 36 would be the max for second in the pairs. When my statement posted above runs it gets the 0 but doesn't get the max value paired with it, it returns 18.
Yes, this is what I was hoping for. Thank you for the time.
(Jan-31-2019, 05:09 PM)ichabod801 Wrote:(Jan-31-2019, 05:03 PM)snowman24 Wrote: I am attempting to get the pair of numbers which contain the min value for the first element and the max for second. In the case above the correct return should be [0,36].
Given that 36 is not the max for the second value, I assume that you want to find the maximum second value among those with the minimum first value. Which is not exactly what you said. To do that, sort by the second value, with reverse = True. Then sort by the first value. The first item will be what you want.
>>> x = [[12, 16], [0, 18], [12, 20], [12, 24], [0, 28], [28, 32], [0, 36], [12, 40], [32, 44], [12, 48]] >>> x.sort(key = lambda a: a[1], reverse = True) >>> x [[12, 48], [32, 44], [12, 40], [0, 36], [28, 32], [0, 28], [12, 24], [12, 20], [0, 18], [12, 16]] >>> x.sort(key = lambda a: a[0]) >>> x [[0, 36], [0, 28], [0, 18], [12, 48], [12, 40], [12, 24], [12, 20], [12, 16], [28, 32], [32, 44]]Edit: clarified my clarification, with code.
Yes, this is what I was hoping for. Thank you for the time.