Skip to content

Instantly share code, notes, and snippets.

@Winand
Last active Jul 1, 2021
Embed
What would you like to do?
Соединить числа в одно максимально возможное
# from functools import total_ordering
# @total_ordering
class Int(int):
def __lt__(self, other):
this, that = str(self), str(other)
YES, NO = True, False
if len(this) < len(that): # everything is vice versa
this, that = that, this
YES, NO = NO, YES
# compare EVERY digit of the longer value to the 1st digit of the other
for i in this:
if i < that[0]:
return YES
return NO
l = [10, 7, 76, 415]
x = ''.join(str(j) for j in sorted((Int(i) for i in l), reverse=True))
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment