wr is a simple, lightweight module that provides random choice based on weights.
Project description
wr (Weighted Random)
wr is a weighted random implementation in Python.
wr.choice can be fed with a mapping (such as dictionaries) containing a returnable (what to return) and a integer representing their respective weight. The key can be anything hashable but the weight must be a integer.
Optionally you may feed wr.choice with a sequence of pairs.
Documentation
Documentation is available at http://wr.readthedocs.org/
Example
>>> import wr >>> data = {'cat': 60, 'dog': 30, 'bird': 10} >>> animal = wr.choice(data) >>> print animal cat # well, the cat had a good 60% shot at it.
Installation
Install wr with pip install wr or just download wr.py and place it in your project directory.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wr-0.2.1.tar.gz
(2.6 kB
view details)
File details
Details for the file wr-0.2.1.tar.gz
.
File metadata
- Download URL: wr-0.2.1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bcc54c1feda299daa0b8cec77d2457892b13a0a7962bedc1d08a494d1d85542 |
|
MD5 | ac7e25966f51ad6a3b29fdcebc38a5bf |
|
BLAKE2b-256 | ec7176fb64c483efee9ac4d23f7c92dbe42551cbacb4fa76881194a047b08b51 |