Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active June 17, 2016 21:16
Show Gist options
  • Save oprypin/0ccd155c5ab4be890f239eed92a3e145 to your computer and use it in GitHub Desktop.
Save oprypin/0ccd155c5ab4be890f239eed92a3e145 to your computer and use it in GitHub Desktop.
def succ(s):
a = list(s)
for i in reversed(range(len(a))):
a[i] = chr(ord(a[i]) + 1)
if a[i] <= 'z':
break
a[i] = 'a'
else:
a.insert(0, 'a')
return ''.join(a)
succ('aaa') # 'aab'
succ('a') # 'b'
succ('xyz') # 'xza'
succ('zzz') # 'aaaa'
succ('ayx') # 'ayy'
succ('lman') # 'lmao'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment