Skip to content

Instantly share code, notes, and snippets.

@asiegman
Created October 30, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asiegman/f882aa3108faacfce15822387a09b8e1 to your computer and use it in GitHub Desktop.
Save asiegman/f882aa3108faacfce15822387a09b8e1 to your computer and use it in GitHub Desktop.
Given an array of letters, find word(s) of the same length that you can spell with those letters.
#!/usr/bin/env python3
words = []
letters = ['a', 'r', 'v', 'b', 'i', 't', 'o']
letters.sort()
# This is the correct path for OSX
f = open('/usr/share/dict/words')
print(f"letters: {letters}")
for line in f:
if len(line.strip()) == len(letters):
words.append(line.strip())
for index in range(0, len(words)):
word_letters = []
for l in words[index].lower():
word_letters.append(l)
word_letters.sort()
if letters == word_letters:
print(words[index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment