I have a list of lists, for example q = [[1,2],[3,4]]
, where each sub-list is a list of 2 integers, and I return the index of each extreme point (I think?).
What I need is the index of the list with the min/max value in the second entry out of all the second entries of the sublists, and where there are other sublists with the same value in the second entry, the index with the min/max first value out of the list of min/max second value entries is returned.
For example, if q = [[1, 2], [3, 4], [1, 0], [0, 5]]
, and I need min second, if tie, then min second and then first. So I need min(S)
to return [1,0]
. Instead, what it seems to return is [0,5]
.
>>> q = [[1,2],[3,4]]
>>> min(q)
[1, 2]
>>> q.append([1,0])
>>> min(q)
[1, 0]
>>> q.append([0,5])
>>> min(q)
[0, 5]
>>> q
[[1, 2], [3, 4], [1, 0], [0, 5]]
According to this answer here, comparing lists compares them in order of the elements, using the next list entry for tie-breakers.
>>> q.append([0,6])
>>> q.append([0,4])
>>> min(q)
[0, 4]
>>> q
[[1, 2], [3, 4], [1, 0], [0, 5], [0, 6], [0, 4]]
>>>
Is there some way I can control the ordering in the comparison? I tried reading through the documentation, but I don't understand what I'm reading.
Does this work for you?