Advertisement
jabela

interlockUSESsets

Aug 5th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #Two words "interlock" if taking alternating letters from each forms a new word.
  2. # For example, "shoe" and "cold" interlock to form "schooled."
  3.  
  4. wordlist = []
  5. wordset = set([])
  6. interlockedwords =[]
  7.  
  8. def interlock(word1,word2):
  9.     interlocked=""
  10.     for i in range(len(word1)):
  11.         interlocked+=(word1[i])
  12.         try:
  13.             interlocked+=(word2[i])
  14.         except:
  15.             break
  16.     return interlocked
  17.  
  18. #Loads file into memory
  19. with open('10000words') as f:
  20.     for line in f:
  21.         line = line.strip()
  22.         wordlist.append(line)
  23.         wordset.add(line)
  24.  
  25. #Sets up word interlocks
  26. wordlist_length=len(wordlist)
  27. print(wordlist_length)
  28. countup = 1
  29.  
  30. for word1 in wordlist:
  31.     print(countup)
  32.     for j in range(countup,wordlist_length):
  33.         word_to_check=interlock(word1,wordlist[j])
  34.         if word_to_check in wordset:
  35.             add_word =(word1,wordlist[j],word_to_check)
  36.             interlockedwords.append(add_word)
  37.             print(add_word)
  38.     countup+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement