How can I get the max pair in the list of pairs with min y?
I got this list:
L =[[1,3],[2,5],[-4,0],[2,1],[0,9]]
With max (L), I get [2.5], but I want [2.1].
max(L, key=lambda item: (item[0], -item[1]))
Conclusion:
[2, 1]
Your query is rather cryptic, but I think this is what you want:
x, y = zip(*L) maxPairs = [L[i] for i,a in enumerate(x) if a == max(x)] returnPair = sorted(maxPairs)[0]
import operator get_y= operator.itemgetter(1) min(L, key=get_y)[0]
Finds a coordinate with a minimum of y, extracts x.
If you do not like it operator.itemgetter, do:
operator.itemgetter
min(L, key=lambda c: c[1])[0]
Source: https://habr.com/ru/post/1794725/More articles:path to android dcim folder - androidIs Visual Studio 2010 coming with SQL Server Express - visual-studio-2010Organizational Tree Construction Algorithm - c #Alternate Application.Run Winform in Program.cs - c #Real time audio input and output streaming in ios - iosEvaluating anonymous functions in a switch statement - anonymous-functionКакие файлы должны быть проверены в SVN из файлов проекта Visual Studio в С#/VB? - version-controlHow to copy DataGridTextColumn style to DataGridTemplateColumn? - silverlightJSF - List of supported browsers - cross-browserAny system for writing code with multiple users in real time, for example, with google public documents? - pythonAll Articles