grabbing random words

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Sep 23 06:55:09 EDT 2006


Jay:
> How would I be able to grab random words from an internet source.  I'd
> like to grab a random word from a comprehensive internet dictionary.
> What would be the best source and the best way to go about this?

Why do you need to grab them from the net?
A simpler solution seems to keep a local file containing the sequence
of words. You can find some open source sequences of such words. Then
you can read all the words in a list, and use random.choice to take one
of them randomly. If you don't want to keep all the dictionary/lexer
(that can be up to 20 MB if it's a lexer) in memory you can (knowing
the len of the file) seek a random position, and read 20-30 bytes, and
take the word inside it (or you can create a dictionary file where each
word is contained in in a fixed len of chars, so you can seek exactly a
single word).

Bye,
bearophile




More information about the Python-list mailing list