![](/img/trans.png)
[英]Returning first element of a tuple after finding the tuple according to the second value in a list of tuples
[英]First tuple value in tuples list based on second value
如何在元组列表中获取元组的第一个值,其中第二个值是次要值?
mylist = [(a, date_a), (b, date_b), ..., (z, date_z)]
如果date_d
是所有日期中的次要日期,我怎样才能得到d
?
min
内置函数实际上接受一个可选的可调用key
作为参数,就像sorted
一样,它更为人所知。
这意味着您可以自定义序列的“最小”含义:
min_item = min(mylist, key item: item[1])[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.