How can I get the first value of a tuple in a tuples list where second value is the minor?
mylist = [(a, date_a), (b, date_b), ..., (z, date_z)]
If date_d
is the minor of all dates how can I get d
?
The min
builtin actually accepts an optional key
callable as a parameter, just like sorted
, where it is more known.
which means you can customize what does it mean to be "minimal" for your sequence:
min_item = min(mylist, key item: item[1])[0]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.