Skip to content

Instantly share code, notes, and snippets.

@bddap
Created March 22, 2018 17:56
Show Gist options
  • Save bddap/3437f9006eb3d1171fd1da9fd2a9f5a8 to your computer and use it in GitHub Desktop.
Save bddap/3437f9006eb3d1171fd1da9fd2a9f5a8 to your computer and use it in GitHub Desktop.
iterate over a subset of pronounceable words
#!/usr/bin/env python3
from itertools import count, product, islice, takewhile
def syllables():
cs = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']
vs = ['a','e','i','o','u']
for c in cs:
for v in vs:
yield c + v
def pronouncables():
for i in count(1):
ps = product(*(syllables() for _ in range(i)))
yield from (''.join(p) for p in ps)
print(' '.join(takewhile(lambda s: len(s) <= 4, pronouncables())))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment