[Tutor] Generate word list from specified letters
Peter Otten
__peter__ at web.de
Sun Jun 30 20:03:25 CEST 2013
Scurvy Scott wrote:
> I'm trying to create a program right now that will pull a dictionary from
> urban dictionary, then use that dictionary as the basis for generating
> words with specified letters.
>
> Maybe I'm not articulating that well enough..
>
> I'm not at all sure where to start and any guidance would be helpful.
>
> I'm running Debian and Python 2.7
I suggest that you start with one part. If you read the words from your
local /usr/share/dict/words file you can concentrate on organising that data
for an efficient lookup. Make it as simple as you can, e. g. implement an
is_matching_word(word, letters)
function and loop over the words file. You need to decide if you care about
repetition -- is letter-count significant, i. e do
'appointing', 'pagination', and 'poignant'
count as equal?
Once you have a working baseline you can think about how to replace the slow
loop with fast dict lookup. What should the dict keys look like? They must
be hashable -- string, tuple or frozenset are promising contenders. What
should the values be? You sure can come up with something for these.
Once you have this running to your satisfaction you can work out how to get
hold of the words from Urban Dictionary. Do they provide a downloadable
list, an API, or do you have to scrape their webpages? If it's the first you
have a drop-in replacement for you local words file, for the other options
you need to write some more code.
More information about the Tutor
mailing list