Created
March 22, 2018 17:56
-
-
Save bddap/3437f9006eb3d1171fd1da9fd2a9f5a8 to your computer and use it in GitHub Desktop.
iterate over a subset of pronounceable words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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