Jan-31-2019, 05:09 PM
(This post was last modified: Jan-31-2019, 05:17 PM by ichabod801.)
(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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures