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 max values using "for loop" when I have to separate lists

I have the following lists and would like to get the maximum values for each person and create a new list using exclusively the for loop and max function. How can I do it?

persons = ['John', 'James', 'Robert']
values = [
    (101, 97, 79),
    (67, 85, 103),
    (48, 201, 105),
]

I’m looking for this ouput:

Output 1 = [('John', 101), ('James', 103), ('Robert', 201]
Output 2 = [101, 103, 201]

Can anyone help?

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

I just do not manage to get this result at all.

>Solution :

output1 = [(i, max(j)) for i,j in zip(persons, values)]
output2 = [max(x) for x in values]
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