Skip to content

Instantly share code, notes, and snippets.

@doubledare704
Created June 23, 2015 15:15
Show Gist options
  • Save doubledare704/fceeb7677338b772958e to your computer and use it in GitHub Desktop.
Save doubledare704/fceeb7677338b772958e to your computer and use it in GitHub Desktop.
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