Skip to content

Instantly share code, notes, and snippets.

@vsanjekar
Last active February 16, 2017 17:50
Show Gist options
  • Select an option

  • Save vsanjekar/3985ac5de67e31cac02506deac12f399 to your computer and use it in GitHub Desktop.

Select an option

Save vsanjekar/3985ac5de67e31cac02506deac12f399 to your computer and use it in GitHub Desktop.
Some code around problems in Letterpress game
#from wordnik import *
#apiUrl = 'http://api.wordnik.com/v4'
#apiKey = '2c07cd1bf3e00c740000803bdbd0bc4ffe1a45a8e22f67fb5'
#client = swagger.ApiClient(apiKey, apiUrl)
#from PyDictionary import PyDictionary
#dictionary=PyDictionary()
# not efficient
def is_subseq(x, y):
it = iter(y)
return all(c in it for c in x)
def intersection(x, y):
common = set(x) & set(y)
return bool(common)
hash = {}
with open('words.txt', 'r') as f:
for line in f:
word = line.split('\n')[0]
key = ''.join(sorted(word))
if key in hash:
hash.get(key).append(word)
else:
hash[key] = [word]
search_word = 'undersaat'
search_exclude = 'io'
search_key = ''.join(sorted(search_word))
exclude_key = ''.join(sorted(search_exclude))
print search_key
print exclude_key
for key in hash:
if is_subseq(search_key,key):
if not intersection(search_exclude, key):
print key, hash[key]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment