Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import copy
- def linker(b):
- for i in range(len(words)):
- if b != i and i not in used:
- 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.
- if b not in used:
- linkedwords.append(words[b])
- used.append(b) #Keeps track of used value's indicies
- linkedwords.append(words[i])
- used.append(i) #Keeps track of used value's indicies
- linker(i) #Recursively checks matches for the next word
- f = open('short dictionary.txt','r')
- words = list()
- length = int(input("Input word length number: \n"))
- for line in f:
- if len(line) == length + 1:
- words.append(line.rstrip('\n')) #Removing newline character and appending
- bestlength = 0
- bestlengthlist = list()
- for c in range(len(words)):
- used = list()
- linkedwords = list()
- linker(c) #Tries a each word as a starting point
- if len(linkedwords) > bestlength:
- bestlength = len(linkedwords)
- bestlengthlist = copy.deepcopy(linkedwords)
- print(bestlengthlist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement