Created
October 30, 2018 20:01
-
-
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.
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 | |
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