Python Forum
programming challenge: double words
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
programming challenge: double words
#7
(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
Reply


Messages In This Thread
programming challenge: double words - by Skaperen - Dec-10-2016, 05:57 AM
RE: programming challenge: double words - by Yoriz - Dec-10-2016, 12:58 PM
RE: programming challenge: double words - by Ofnuts - Dec-12-2016, 12:49 AM
RE: programming challenge: double words - by Ofnuts - Dec-14-2016, 07:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Where is a "Challenge" forum? wavic 2 3,680 Nov-08-2016, 11:45 AM
Last Post: Kebap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020