Skip to content

Instantly share code, notes, and snippets.

@Winand
Last active July 1, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Winand/ef56e6ad739e4756fb1b63af72831b68 to your computer and use it in GitHub Desktop.
Save Winand/ef56e6ad739e4756fb1b63af72831b68 to your computer and use it in GitHub Desktop.
Соединить числа в одно максимально возможное
# 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