skip to navigation
skip to content

Not Logged In

wr 0.2.1

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

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 is available at


>>> 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.


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



File Type Py Version Uploaded on Size
wr-0.2.1.tar.gz (md5) Source 2012-07-03 2KB
  • Downloads (All Versions):
  • 34 downloads in the last day
  • 169 downloads in the last week
  • 619 downloads in the last month