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

How to print the highest number in lists that are inside another list

I want to print the highest number from my list (1231 here).
I tried doing this here (posted below), but that doesn’t work. It just shows the highest total number for each element in my list, which is, obviously, not what I want.

list = [ [1,3,251], [2], [1231,52,22] ]

for i in range(len(list)):
    for j in range(len(list[i])):
        print(max(list))

prints:

[1231, 52, 22]
[1231, 52, 22]
[1231, 52, 22]
[1231, 52, 22]
[1231, 52, 22]
[1231, 52, 22]
[1231, 52, 22]

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 :

list = [ [1,3,251], [2], [1231,52,22] ]
new_list = []
for i in list:
    new_list.append(max(i))
print(max(new_list))

This will do. This will print only the highest number from the entire list.

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