SHARE
TWEET

Untitled

a guest Feb 2nd, 2011 437 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2.  
  3. from Levenshtein import distance
  4.  
  5. WORD = 'causes'
  6.  
  7. word_list = map(str.strip, file('word.list').readlines())
  8.  
  9. dists = {}
  10.  
  11. for word in word_list:
  12.     dists.setdefault(distance(word, WORD), []).append(word)
  13.    
  14. friends = []
  15. old_friends = [WORD]
  16. for dist, words in sorted(dists.items())[1:]:
  17.     print dist, len(words), len(friends)
  18.     new_friends = []
  19.     for word in words:
  20.         for friend in old_friends:
  21.             if distance(friend, word) == 1:
  22.                 new_friends.append(word)
  23.                 break
  24.     if new_friends:
  25.         friends.extend(new_friends)
  26.         old_friends = new_friends
  27.     else:
  28.         print 'DONE:', len(friends)
  29.         sys.exit()
  30.  
  31. 1 18 0
  32. 2 232 18
  33. 3 2262 128
  34. 4 12622 848
  35. 5 34862 3859
  36. 6 45920 9937
  37. 7 44139 13812
  38. 8 39836 14166
  39. 9 30594 14206
  40. 10 21427 14207
  41. DONE: 14207
RAW Paste Data
Top