0

I have a list of lists and I need to find the maximum value of each list, but I don't know how to do it.

l = [['6', '6', '11', '12', '10', '6', '9', '10', '6'], ['4'], ['6', '20', '10', '6', '10', '7', '8'], ['8', '4', '1', '5', '5']] 

The maximum values ​​have to come back in a list, because then I'll have to sum them. Example:

max_values = [12, 4, 20, 8] 

2 Answers 2

5

You can use a simple list comprehension with max to get the biggest value and map to convert all elements to int:

max_values = [max(map(int, i)) for i in l] 
Sign up to request clarification or add additional context in comments.

Comments

0

Try using lamda and the max built-in function in combination, or map the list and use max afterwords: https://stackoverflow.com/a/18296814/13526701 Or https://stackoverflow.com/a/70155571/13526701

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.