From: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com> |
---|---|
To: | |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Finding matching words in a word game |
Date: | 2013-03-06 14:14:43 |
Message-ID: | CAADeyWgVQY=-jRCwwrXoArDTDf=uj5K8hj9KRVjZW2qnEybXbg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks, will try that (the "dumb" approach) too :-)
Still working on my dictionary (will be auto-generated by a script).
On Wed, Mar 6, 2013 at 2:57 PM, Chris Angelico <rosuav(at)gmail(dot)com> wrote:
> words = {}
> for word in dictionary: # provide a dictionary somehow - maybe from a file/db
> words.setdefault(''.join(sorted(word)),[]).append(word)
> # Voila! You now have your mapping. One-off initialization complete.
>
> find_anagrams_of = "stop"
> anagrams = words.get(''.join(sorted(find_anagrams_of)),[])
> # anagrams is now a list of all known anagrams of the target -
> possibly an empty list
> print(anagrams)
>
>
> ['opts', 'post', 'pots', 'spot', 'stop', 'tops']
>
> On my laptop, loading ~100K words took about 1 second, and the lookup
> took effectively no time. I don't think there's any need for a heavy
> database engine here, unless you're working with millions and millions
> of words :)
>
> Chris Angelico
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
From | Date | Subject | |
---|---|---|---|
Next Message | Florian Weimer | 2013-03-06 14:24:46 | Re: [GENERAL] Floating point error |
Previous Message | Chris Angelico | 2013-03-06 13:57:28 | Re: Finding matching words in a word game |