Created
September 19, 2016 16:48
-
-
Save huntwelch/1c40cff74a6e0c7b88bce2f5874f67ea to your computer and use it in GitHub Desktop.
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
| f = open('/usr/share/dict/words') | |
| words = f.readlines() | |
| f.close() | |
| words = [x.strip() for x in words if x.islower()] | |
| check = set(words) | |
| inputword = 'dick' | |
| def spoonit(word): | |
| spoon_1 = ''.join([word[:1], inputword[1:]]) | |
| spoon_2 = ''.join([inputword[:1], word[1:]]) | |
| if spoon_1 not in check: return False | |
| if spoon_2 not in check: return False | |
| return ' '.join([spoon_1, spoon_2]) | |
| spoons = map(spoonit, words) | |
| view = [x for x in spoons if x] | |
| print '\n'.join(view) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The last part might be faster as
if set([w[:1] + inputword[1:], inputword[:1] + word[1:]]).issubset(check)