I am trying to sort numerical tuples by two arguments:
- first argument, lenght of the tuple: the smaller the tuple, the better;
- second argument, the n-th value of the tuple: if two tuples have the same lenght, then they should be ordered by the first numerical value by which they differ
For example, let's say we have these four tuples:
a = (2, 5) # len(a) == 2
b = (2, 5, 3) # len(b) == 3
c = (2, 4, 3) # len(c) == 3
d = (1, 4, 4, 8) # len(d) == 4
The result I'm willing to obtain is a function that will help me sort these tuples so that:
- a is the first tuple (the smallest one)
- b and c follows (the middle ones)
- d is the last tuple (the longest one)
- since b and c both get the same lenght, they shall be ordered so that c comes before b, because while their first value is the same, c's second values is smaller than b's
Therefore, the four tuples above should be listed as [a, c, b, d].
Question is: how do I do it, knowing that the tuples have no fixed length, and they might differ at any value from the first to the last one?