Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. import copy
  2.  
  3. def linker(b):
  4.     for i in range(len(words)):
  5.         if b != i and i not in used:
  6.             if words[b][-3] == words[i][1] and words[b][-2] == words[i][2]:  ##Compares 3rd last and 2nd last letters to 2nd and 3rd letters.
  7.                 if b not in used:
  8.                     linkedwords.append(words[b])
  9.                     used.append(b)  #Keeps track of used value's indicies
  10.                 linkedwords.append(words[i])
  11.                 used.append(i)  #Keeps track of used value's indicies
  12.                 linker(i)    #Recursively checks matches for the next word
  13.  
  14. f = open('short dictionary.txt','r')
  15. words = list()
  16. length = int(input("Input word length number: \n"))
  17.  
  18. for line in f:
  19.     if len(line) == length + 1:
  20.         words.append(line.rstrip('\n')) #Removing newline character and appending
  21.  
  22. bestlength = 0
  23. bestlengthlist = list()
  24.  
  25. for c in range(len(words)):
  26.     used = list()
  27.     linkedwords = list()
  28.     linker(c)   #Tries a each word as a starting point
  29.     if len(linkedwords) > bestlength:
  30.         bestlength = len(linkedwords)
  31.         bestlengthlist = copy.deepcopy(linkedwords)
  32.  
  33. print(bestlengthlist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement