Reading a local word list

If you're doing this repeatedly, I would download it locally and pull from the local file. *nix users can use /usr/share/dict/words.

Example:

word_file = "/usr/share/dict/words"
WORDS = open(word_file).read().splitlines()

Pulling from a remote dictionary

If you want to pull from a remote dictionary, here are a couple of ways. The requests library makes this really easy (you'll have to pip install requests):

import requests

word_site = "https://www.mit.edu/~ecprice/wordlist.10000"

response = requests.get(word_site)
WORDS = response.content.splitlines()

Alternatively, you can use the built in urllib2.

import urllib2

word_site = "https://www.mit.edu/~ecprice/wordlist.10000"

response = urllib2.urlopen(word_site)
txt = response.read()
WORDS = txt.splitlines()
Answer from Kyle Kelley on Stack Overflow
🌐
GitHub
github.com › jweinst1 › Random-Word-Generator
GitHub - jweinst1/Random-Word-Generator: A python program that generates random words of a specific length and starting letter. Uses an algorithm that only makes words based on English grammar rules. Useful for coming up with new names for businesses or apps.
A python program that generates random words of a specific length and starting letter. Uses an algorithm that only makes words based on English grammar rules. Useful for coming up with new names for businesses or apps.
Starred by 7 users
Forked by 6 users
Languages   HTML 58.2% | Python 41.8% | HTML 58.2% | Python 41.8%
🌐
GitHub
github.com › topics › random-word-generator
random-word-generator · GitHub Topics · GitHub
This library helps you to create random words i.e noise in text data. Helpful in many tasks like the generation of random authorization token generation of constant or variable length, text data augmentation, etc. python natural-language-processing ...
🌐
GitHub
github.com › AbhishekSalian › Random-Word-Generator
GitHub - AbhishekSalian/Random-Word-Generator: This library helps you to create random words i.e noise in text data. Helpful in many tasks like the generation of random authorization token generation of constant or variable length, text data augmentation, etc. · GitHub
pip3 install Random-Word-Generator OR pip install Random-Word-Generator · No need of any external packages · Only Python version >= 3 is required · It helps us to generate random words i.e random noise in text data which is helpful in many ...
Author   AbhishekSalian
🌐
GitHub
github.com › ggouzi › markov-word-generator
GitHub - ggouzi/markov-word-generator: A small Python library to generate random credible words based on a list of words by estimating the probability of the next character from the frequency of the previous ones · GitHub
Markov-Word-Generator is a Python library for generating random, credible, and plausible words based on a list of words. It estimates the probability of the next character in a word based on the frequency of the previous N characters, using ...
Starred by 8 users
Forked by 3 users
Languages   Python
🌐
GitHub
github.com › vaibhavsingh97 › random-word
GitHub - vaibhavsingh97/random-word: This is a simple python package to generate random english words
This is a simple python package to generate random english words - vaibhavsingh97/random-word
Starred by 126 users
Forked by 24 users
Languages   Python 91.7% | Makefile 8.3% | Python 91.7% | Makefile 8.3%
🌐
GitHub
github.com › SaiWebApps › RandomWordGenerator
GitHub - SaiWebApps/RandomWordGenerator: Python Library for Generating Random Words
Python Library for Generating Random Words. Contribute to SaiWebApps/RandomWordGenerator development by creating an account on GitHub.
Author   SaiWebApps
🌐
GitHub
github.com › mrmaxguns › wonderwordsmodule
GitHub - mrmaxguns/wonderwordsmodule: Generate random words and sentences with ease in Python. Be on the lookout for bugfixes and speed improvements in 2.3
from wonderwords import RandomWord r = RandomWord() # generate a random word r.word() # random word that starts with a and ends with en r.word(starts_with="a", ends_with="en") # generate a random noun or adjective, by default all parts of speech ...
Starred by 70 users
Forked by 13 users
Languages   Python 100.0% | Python 100.0%
Top answer
1 of 8
122

Reading a local word list

If you're doing this repeatedly, I would download it locally and pull from the local file. *nix users can use /usr/share/dict/words.

Example:

word_file = "/usr/share/dict/words"
WORDS = open(word_file).read().splitlines()

Pulling from a remote dictionary

If you want to pull from a remote dictionary, here are a couple of ways. The requests library makes this really easy (you'll have to pip install requests):

import requests

word_site = "https://www.mit.edu/~ecprice/wordlist.10000"

response = requests.get(word_site)
WORDS = response.content.splitlines()

Alternatively, you can use the built in urllib2.

import urllib2

word_site = "https://www.mit.edu/~ecprice/wordlist.10000"

response = urllib2.urlopen(word_site)
txt = response.read()
WORDS = txt.splitlines()
2 of 8
20

Solution for Python 3

For Python3 the following code grabs the word list from the web and returns a list. Answer based on accepted answer above by Kyle Kelley.

import urllib.request

word_url = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
response = urllib.request.urlopen(word_url)
long_txt = response.read().decode()
words = long_txt.splitlines()

Output:

>>> words
['a', 'AAA', 'AAAS', 'aardvark', 'Aarhus', 'Aaron', 'ABA', 'Ababa',
 'aback', 'abacus', 'abalone', 'abandon', 'abase', 'abash', 'abate',
 'abbas', 'abbe', 'abbey', 'abbot', 'Abbott', 'abbreviate', ... ]

And to generate (because it was my objective) a list of 1) upper case only words, 2) only "name like" words, and 3) a sort-of-realistic-but-fun sounding random name:

import random
upper_words = [word for word in words if word[0].isupper()]
name_words  = [word for word in upper_words if not word.isupper()]
rand_name   = ' '.join([name_words[random.randint(0, len(name_words))] for i in range(2)])

And some random names:

>>> for n in range(10):
        ' '.join([name_words[random.randint(0,len(name_words))] for i in range(2)])

    'Semiramis Sicilian'
    'Julius Genevieve'
    'Rwanda Cohn'
    'Quito Sutherland'
    'Eocene Wheller'
    'Olav Jove'
    'Weldon Pappas'
    'Vienna Leyden'
    'Io Dave'
    'Schwartz Stromberg'
Find elsewhere
🌐
GitHub
github.com › greghaskins › gibberish
GitHub - greghaskins/gibberish: Python pseudo-word generator
The gibberish module let's you generate random, pronounceable pseudo-words.
Starred by 85 users
Forked by 17 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › topics › random-words
random-words · GitHub Topics · GitHub
Generate random words and sentences with ease in Python.
🌐
PyPI
pypi.org › project › random_word
random_word · PyPI
Assuming that you have Python and pipenv installed, set up your environment and install the required dependencies like this instead of the pip install random-word defined above: $ git clone https://github.com/vaibhavsingh97/random-word.git $ cd random-word $ make init
      » pip install random_word
    
Published   Nov 21, 2024
Version   1.0.13
🌐
GitHub
github.com › imset › Random-Word-Generator
GitHub - imset/Random-Word-Generator: Randomly generates a (theoretically) pronounceable word.
July 26, 2020 - Randomly generates a (theoretically) pronounceable word. It basically generates a word with a length of your choosing. It's (probably) not a real word, whatever it is that you generate.
Author   imset
🌐
GitHub
gist.github.com › bergantine › 2390284
Python String Generator of "Random" English Nouns. #python #password · GitHub
word_list = [] with open('word_list.txt') as f: # or whatever the wordlist is saved as for line in f.readlines(): index, word = line.strip().split('\t') word_list.append(word) print " ".join([word_list[random.randrange(0, len(word_list))] for ...
🌐
GitHub
github.com › 8nhuman8 › randword
GitHub - 8nhuman8/randword: The Python package for generating random English words · GitHub
The Python package for generating random English words - 8nhuman8/randword
Author   8nhuman8
🌐
PyPI
pypi.org › project › RandomWords
RandomWords · PyPI
Software Development :: Libraries :: Python Modules · Report project as malware · RandomWords is a useful package for generate random words, nicks, e-mails and lorem ipsum. Quick way: pip install RandomWords · or: git clone https://githu...
      » pip install RandomWords
    
Published   Aug 27, 2022
Version   0.4.0
🌐
GitHub
github.com › tirthajyoti › FunnyWordGen
GitHub - tirthajyoti/FunnyWordGen: Funny word (random) generator using Python 3 · GitHub
September 29, 2024 - Funny word (random) generator using Python 3. Contribute to tirthajyoti/FunnyWordGen development by creating an account on GitHub.
Starred by 2 users
Forked by 9 users
Languages   Python
🌐
GitHub
github.com › topics › random-word
random-word · GitHub Topics · GitHub
A simple python script that generates a hangman game using a word randomly chosen from a separate txt file.
🌐
GitHub
github.com › HinaAmano2021 › Random-Word-Generator
GitHub - HinaAmano2021/Random-Word-Generator
Random Word Generator.py · View code · No description, website, or topics provided. Readme · 0 stars · 1 watching · 0 forks · No releases published · No packages published · Python 100.0% You can’t perform that action at this time. You signed in with another tab or window.
Author   HinaAmano2021
🌐
GitHub
github.com › tommyyearginjr › random-word-generator
GitHub - tommyyearginjr/random-word-generator: This script generates a list of words five letters in length or longer mined from a text file, and outputs a random word.
This script generates a list of words five letters in length or longer mined from a text file, and outputs a random word. - tommyyearginjr/random-word-generator
Author   tommyyearginjr
🌐
Dmulholl
dmulholl.com › blog › lets-build-a-markov-chain-word-generator.html
Let's Build a Markov-Chain Word Generator in Python
November 14, 2020 - We'll use a Markov chain to generate new words based on a corpus of sample words — this way we can generate words with whatever 'flavour' we like, just by tailoring the input data. You can find the code for this project on Github. We actually don't need very much code at all — this is the ...