Guest User

Untitled

a guest
Jul 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. def alphabet_range(start_with, limit):
  2. alphabet = '$abcdefghijklmnopqrstuvwxyz' # alphabet set, don't modify it
  3. i = 0
  4. n = 0
  5. while n < limit: # from 1 to some number
  6. w = []
  7. k = i
  8. while k > 0:
  9. w.append(alphabet[k % 27]) # shortcut for enumeration, covert to 27-ary number
  10. k = k / 27
  11. i += 1
  12. if w.count('$') > 0:
  13. continue
  14. w.reverse() # reverse the list (otherwise will be aa, ba, ca, da, strange)
  15. word = ''.join(w) # generate string
  16. if start_with is not None and word != start_with: #check if it is start string, if not, continue
  17. continue
  18. start_with = None # if it is, start from here, output every string
  19. n += 1
  20. yield word # output generated string
  21.  
  22. for word in alphabet_range('abc', 1000):
  23. print word
Add Comment
Please, Sign In to add comment