Соединить числа в одно максимально возможное
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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