0

Trying to find min value of this tuple:

`min(
(10.0, ((-9990, 0), (-9980, 0))), 
(10.0, (-9960, 0), (-9950, 0))
)` 

I am using the min function in python. However, I get this error: TypeError: '<' not supported between instances of 'int' and 'tuple'. It seems to have something to-do with the zeros as this works:

`min(
(3426.842861877387, ((8590, 4206), (8666, 7632))), 
(182.7840255602223, (8675, -5692), (8712, -5513))
)`

Any ideas what I can do instead, the formatting seems to be the same in both of these examples.

  • Are you trying to find the minimal number regardless of its depth in the tuple? – Altareos Apr 20 '21 at 07:17
  • What do you mean by "this works"? `min(115.45128842936315, ((-1842, 1054), (-1794, 1159)))` won't work either. – Selcuk Apr 20 '21 at 07:17
  • Edited my question with more info. – Victor Gunnarsson Apr 20 '21 at 07:19
  • What is the expected output for : min((34.92849839314596, (6856, -7293), (6848, -7259)), (40.607881008493905, ((-5110, 4518), (-5085, 4486)))) ? It's returning tuples only. "(34.92849839314596, (6856, -7293), (6848, -7259))" – Shubham Periwal Apr 20 '21 at 07:25
  • This has nothing with zeros to do. "This works" because you are comparing tuples with tuples; `(34.92849839314596, (6856, -7293), (6848, -7259))` is smaller than `(40.607881008493905, ((-5110, 4518), (-5085, 4486))`and the comparison is well-defined. But Python doesn't know how to compare `((-9990, 0), (-9980, 0))` with `(-9960, 0)` and thus you get the traceback. – tripleee Apr 20 '21 at 07:27
  • In your first example the tuples are not of the same size. Count your parentheses, i.e. `((-9990, ...` vs `(-9660, ...`. Try `min((10.0, (-9990, 0), (-9980, 0)), (10.0, (-9960, 0), (-9950, 0)))`. – Selcuk Apr 20 '21 at 07:27
  • The formatting is the same, I have taken another example and formatted it better this time. – Victor Gunnarsson Apr 20 '21 at 07:34

0 Answers0