Skip to content

Instantly share code, notes, and snippets.

@JacobHearst
Created September 26, 2017 20:06
Show Gist options
  • Save JacobHearst/c26875dfd19446dcfe88c8aff61c6d73 to your computer and use it in GitHub Desktop.
Save JacobHearst/c26875dfd19446dcfe88c8aff61c6d73 to your computer and use it in GitHub Desktop.
A simple rhyme finder built off of the api from datamuse
import json
from urllib.request import urlopen
HEADERS = ["One", "Two", "Three", "Four or more", "======"]
BORDER = "======"
url = "https://api.datamuse.com/words?rel_rhy=" + \
input("Input a word to find out what rhymes: ").split(' ')[0]
data = json.load(urlopen(url))
syl_arrays = {}
for var in range(0, 4):
syl_arrays[var] = [datum['word']
for datum in data if datum['numSyllables'] is var + 1]
for index, array in enumerate(syl_arrays):
if syl_arrays[index]:
print("%s %s Syllable Rhymes %s" % (BORDER, HEADERS[index], BORDER))
for word in syl_arrays[index]:
stuff = 1
print(word, end=' ', sep=' ', flush=True)
print('\n')
found = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment