1
test2_list = [[], [3], [1,2], [2,4], [1,2,3], [2,3,4]]
maxList = max((x) for x in test2_list)

I am getting output as [3], but it should be [2,3,4].

Red
  • 26,798
  • 7
  • 36
  • 58
  • 6
    When two lists are compared, it starts with the first element; if they are the same, then it proceeds to the second one, etc. So `[3]` is the maximum in this case. – alani Jul 12 '20 at 21:58
  • Why do you think `[2,3,4]` should be the answer? What is the rule that tells you that this is "greater" than the other elements? How exactly do you want to compare them? – Karl Knechtel Jul 16 '20 at 20:33

1 Answers1

2

I think you're looking to compare based on the sum given your expected output and input given.

The reason for the output you got was well given in the comment by alaniwi although you're looking to use the key arg for max

maxList = max(test2_list, key=sum)
10 Rep
  • 2,217
  • 7
  • 19
  • 33
Jab
  • 26,853
  • 21
  • 75
  • 114