Created
June 23, 2015 15:15
-
-
Save doubledare704/fceeb7677338b772958e to your computer and use it in GitHub Desktop.
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
def compareInteger(a,b): | |
stringa = str(a) | |
stringb = str(b) | |
for i in xrange(min(len(stringa), len(stringb))): | |
if stringa[i] > stringb[i]: | |
return 1 | |
elif stringa[i] < stringb[i]: | |
return -1 | |
if len(stringa) > len(stringb): | |
return compareInteger(stringa[len(stringb):], stringb) | |
elif len(stringa) < len(stringb): | |
return compareInteger(stringa, stringb[len(stringa):]) | |
else: | |
return 0 | |
def numbering(numlist): | |
return int(''.join('{}'.format(n) for n in numlist)) | |
nums = [4, 94, 9, 14, 1] | |
sortednums = sorted(nums, cmp = compareInteger, reverse = True) | |
print nums | |
print sortednums | |
print numbering(sortednums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment