Dec-12-2016, 12:49 AM
(Dec-10-2016, 02:20 PM)ichabod801 Wrote: Mine is similar to Yoriz's, but using sets:
def double_words(word_list): word_set = set(word_list) doubles = set(''.join(pair) for pair in itertools.permutations(word_list, 2) if ''.join(pair) in word_set) return [word for word in word_list if word in doubles]It works on Yoriz's word list. I ran it on the full word list I normally use. It ran quite a while and found 15,876 double words.
No time for code, but:
- build a set of all the words
- scan the llist again, and for each word iterate
x
see if word[:x]
is in the set, and if so if word[x:]
is also in the set. No need for the N**2 set. Complexity is O(N*L) where L is the average half-length but since it's practically a constant for large sets of random words, result must be O(N).
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Your one-stop place for all your GIMP needs: gimp-forum.net