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

Find tuple in list of tuples in python

I have a list of tuple (simulationtime,efficiency) and I want to find the tuple in which the maximum efficiency is stated with respect to the minimum simulation time. Any hints on how that could be done?
A small part of the otherwise very large list:

[(109.00537427472713, 0.8), (109.00588429136333, 0.85), (109.00649436705454, 0.86), (110.00055419961151, 0.86), (110.00122432147343, 0.86), (110.00172424060818, 0.86), (110.00236418239592, 0.86), (110.00292411815163, 0.86)]

I want the output to be (109.00649436705454, 0.86) from the list since it corresponds to max efficiency at min simulation time. Right now I am doing:

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

next(v for v in AoD_log if v[1] >= 0.85)

but the maximum achievable efficiency: index[1] of the tuple is not always known.

>Solution :

your_list = [(109.00537427472713, 0.8), (109.00588429136333, 0.85), (109.00649436705454, 0.86), (110.00055419961151, 0.86), (110.00122432147343, 0.86), (110.00172424060818, 0.86), (110.00236418239592, 0.86), (110.00292411815163, 0.86)]
max_efficiency = max(your_list, key=lambda x : x[1])[1]
min_simulation_time = min((x for x in your_list if x[1]==max_efficiency))

Output:

(109.00649436705454, 0.86)
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