Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Two words "interlock" if taking alternating letters from each forms a new word.
- # For example, "shoe" and "cold" interlock to form "schooled."
- wordlist = []
- wordset = set([])
- interlockedwords =[]
- def interlock(word1,word2):
- interlocked=""
- for i in range(len(word1)):
- interlocked+=(word1[i])
- try:
- interlocked+=(word2[i])
- except:
- break
- return interlocked
- #Loads file into memory
- with open('10000words') as f:
- for line in f:
- line = line.strip()
- wordlist.append(line)
- wordset.add(line)
- #Sets up word interlocks
- wordlist_length=len(wordlist)
- print(wordlist_length)
- countup = 1
- for word1 in wordlist:
- print(countup)
- for j in range(countup,wordlist_length):
- word_to_check=interlock(word1,wordlist[j])
- if word_to_check in wordset:
- add_word =(word1,wordlist[j],word_to_check)
- interlockedwords.append(add_word)
- print(add_word)
- countup+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement