Mar-20-2019, 03:21 PM
(This post was last modified: Mar-20-2019, 03:22 PM by ichabod801.)
Well, you haven't defined what you mean by similar. Obviously you know how to sort using key functions. If you can define a function such that all similar values get transformed into the same value, you can just use a key function. For example, if you want to ignore the ones digit, you could just use
But say your similarity is "within 10 of the next value". That you can't define a simple function for. You may need to augment your lists with a fourth value. That is, sort by y. Then add a fourth item to each sublist that is the same as the previous sublist's fourth value if they are within 10 of each other, otherwise it's one greater. Then sort by the fourth item and the first item (x).
lambda x: x[1] // 10, x[0]
.But say your similarity is "within 10 of the next value". That you can't define a simple function for. You may need to augment your lists with a fourth value. That is, sort by y. Then add a fourth item to each sublist that is the same as the previous sublist's fourth value if they are within 10 of each other, otherwise it's one greater. Then sort by the fourth item and the first item (x).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures