Skip to main content

wr is a simple, lightweight module that provides random choice based on weight

Project description

wr is a weighted random implementation in Python.

wr.get returns a key of a passed in dict based on the weights of the keys as their respective values. {key: weight} The key can be anything hashable including callables but the weight must be a integer.

Example

>>> import wr

>>> data = {'cat': 60, 'dog': 30, 'bird': 10}
>>> animal = wr.get(data)
>>> print animal
cat # well, the cat had a good 60% shot at it.

Installation and Dependencies

Install wr with pip install wr or just download wr.py and place it in your project directory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for wr, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size wr-0.1.1.tar.gz (2.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page