Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

First tuple value in tuples list based on second value

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The min builtin actually accepts an optional key callable as a paramter, just like sorted were that 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]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading