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]
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
michelascr
  • 11
  • 2

2 Answers2

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]
Pedro Maia
  • 2,666
  • 1
  • 5
  • 20
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

NoBlockhit
  • 369
  • 2
  • 15