Skip to content

Instantly share code, notes, and snippets.

@rioleo
Created November 16, 2011 16:39
Show Gist options
  • Save rioleo/1370589 to your computer and use it in GitHub Desktop.
Save rioleo/1370589 to your computer and use it in GitHub Desktop.
lexicographic
def lexicographic(word):
word = list(word)
for i in range(len(word) - 1):
if (ord(word[i]) < ord(word[i + 1])):
k = i
for l in range(len(word)):
if (ord(word[l]) > ord(word[k])):
j = l
word[k], word[l] = word[l], word[k]
return "".join(word[:k+1] + word[k+1:][::-1])
print lexicographic("abcde")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment