get the words online
from urllib.request import Request, urlopen
url="//svnweb.freebsd.org/csrg/share/dict/words?revision=61569&view=co"
req = Request[url, headers={'User-Agent': 'Mozilla/5.0'}]
web_byte = urlopen[req].read[]
webpage = web_byte.decode['utf-8']
print[webpage]
Randomizing the first 500 words
from urllib.request import Request, urlopen
import random
url="//svnweb.freebsd.org/csrg/share/dict/words?revision=61569&view=co"
req = Request[url, headers={'User-Agent': 'Mozilla/5.0'}]
web_byte = urlopen[req].read[]
webpage = web_byte.decode['utf-8']
first500 = webpage[:500].split["\n"]
random.shuffle[first500]
print[first500]
Output
['abnegation', 'able', 'aborning', 'Abigail', 'Abidjan', 'ablaze', 'abolish', 'abbe', 'above', 'abort', 'aberrant', 'aboriginal', 'aborigine', 'Aberdeen', 'Abbott', 'Abernathy', 'aback', 'abate', 'abominate', 'AAA', 'abc', 'abed', 'abhorred', 'abolition', 'ablate', 'abbey', 'abbot', 'Abelson', 'ABA', 'Abner', 'abduct', 'aboard', 'Abo', 'abalone', 'a', 'abhorrent', 'Abelian', 'aardvark', 'Aarhus', 'Abe', 'abjure', 'abeyance', 'Abel', 'abetting', 'abash', 'AAAS', 'abdicate', 'abbreviate', 'abnormal', 'abject', 'abacus', 'abide', 'abominable', 'abode', 'abandon', 'abase', 'Ababa', 'abdominal', 'abet', 'abbas', 'aberrate', 'abdomen', 'abetted', 'abound', 'Aaron', 'abhor', 'ablution', 'abeyant', 'about']
This post goes over how to generate a random word or letter in Python. Install random-word and PyYaml:Install
pip3 install random-word pyyaml
PyYaml is required or else you’ll get the error:
ModuleNotFoundError: No module named 'yaml'
Usage
Generate a random word:
from random_word import RandomWords
random_words = RandomWords[]
print[random_words.get_random_word[]]
See the package documentation for more information.
Demo
Replit:
Random Letter
Get a random letter from the alphabet:
from string import ascii_lowercase
from random import randrange
print[ascii_lowercase[randrange[len[ascii_lowercase]]]]
Demo
Replit:
Please support this site and join our Discord!
Project description
This is a simple python package to generate random English words. If you need help after reading the below, please find me on Twitter at @vaibhavsingh97.
If you love the package, please :star2: the repo.
Installation
You should be able to install using easy_install
or pip
in the usual ways:
$ easy_install random-word $ pip install random-word
Or clone this repository and run:
$ python3 setup.py install
Or place the random-word
folder that you downloaded somewhere where your scripts can access it.
Basic Usage
👋 This package will now, by default, fetch the random word from local database
from random_word import RandomWords r = RandomWords[] # Return a single random word r.get_random_word[]
Different services are available as a part of the random word package, which fetches random words from various API providers. Please check the Services
section for more details.
Services
- Wordnik
- API Ninjas
Development
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 //github.com/vaibhavsingh97/random-word.git
$ cd random-word
$ make init
Add API Key in random_word
directory defining API Key in config.yml
. If you don't have an API key, then request your API key [here][wornikWebsiteLink]
API_KEY = ""
To check your desired changes, you can install your package locally.
$ pip install -e .
Issues
You can report the bugs at the issue tracker
License
Built with ♥ by Vaibhav Singh[@vaibhavsingh97] under MIT License
You can find a copy of the License at //vaibhavsingh97.mit-license.org/
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.