Advertisement
Guest User

Pyton diner/dinner - with hash

a guest
Feb 23rd, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. nawords = getwords("enable-wordlist.txt")
  2.  
  3. # Create a hash, aka dictionary, for fast lookup of words
  4. nahash = {w:True for w in nawords}
  5.  
  6. # Generate set of possible "words" by doubling every character
  7. def dcands(w):
  8. return set([w[:i] + w[i] + w[i:] for i in range(len(w))])
  9.  
  10. # Generate list of all valid (baseword, transformed word) pairs
  11. def dopfast(ws, wordhash):
  12. return [(w,c) for w in ws for c in dcands(w) if wordhash.get(c, False)]
  13.  
  14. dopfast(nawords, nahash)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement