Skip to content

Instantly share code, notes, and snippets.

@liuliu
Created December 12, 2010 04:12
Show Gist options
  • Save liuliu/737837 to your computer and use it in GitHub Desktop.
Save liuliu/737837 to your computer and use it in GitHub Desktop.
def alphabet_range(start_with, limit):
alphabet = '$abcdefghijklmnopqrstuvwxyz' # alphabet set, don't modify it
i = 0
n = 0
while n < limit: # from 1 to some number
w = []
k = i
while k > 0:
w.append(alphabet[k % 27]) # shortcut for enumeration, covert to 27-ary number
k = k / 27
i += 1
if w.count('$') > 0:
continue
w.reverse() # reverse the list (otherwise will be aa, ba, ca, da, strange)
word = ''.join(w) # generate string
if start_with is not None and word != start_with: #check if it is start string, if not, continue
continue
start_with = None # if it is, start from here, output every string
n += 1
yield word # output generated string
for word in alphabet_range('abc', 1000):
print word
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment