-2

max((12,1),(1,),(2,1,2) : So is it a wrong format to check which tuple is the greatest respective to the number of values in the tuple?

Because only the first value of each tuple is considered in this case.

1 Answers1

2

If you want to treat the longest tuple as the maximum, you need to specify a different key function:

>>> max((12,1),(1,),(2,1,2), key=len)
(2, 1, 2)

By default, tuples are compared lexicographically, meaning the second element of two tuples is only considered if the first elements are equal. (The empty tuple is less than or equal to any other tuple.)

chepner
  • 497,756
  • 71
  • 530
  • 681