Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
最小yのペアのリストで最大ペアを取得するにはどうすればよいですか?
私はこのリストを手に入れました:
L =[[1,3],[2,5],[-4,0],[2,1],[0,9]]
max(L) を使用すると [2,5] が得られますが、[2,1] が必要です。
max(L, key=lambda item: (item[0], -item[1]))
出力:
[2, 1]
あなたの要求はちょっと不可解ですが、これがあなたが望むものだと思います:
x, y = zip(*L) maxPairs = [L[i] for i,a in enumerate(x) if a == max(x)] returnPair = sorted(maxPairs)[0]