michelascr
michelascr

Reputation: 11

Max values in list of lists

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]

Upvotes: 0

Views: 2266

Answers (2)

NoBlockhit
NoBlockhit

Reputation: 409

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

Upvotes: 0

Pedro Maia
Pedro Maia

Reputation: 2712

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]

Upvotes: 5

Related Questions