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

Take list of values and find biggest combination between certain amount of items in the list

I have a list of values that has a size of 24.

What I want to do is find the biggest combination using three values from the list. I only want to use three of the values, the highest ones possible.

So if I had a list that looked like:

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

vals_list = [5, 3, 5, 5, 5, 4, 2, 1, 2, 4]

My desired output would be 15, as it would take three of the ‘5’ values in the list and sum them together. Is there any possible way to do this in python?

>Solution :

IIUC sorting values and extract last 3 values for top3, last sum them:

print (sum(sorted(vals_list)[-3:]))
15
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