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.

License

GNU Lesser General Public 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.1.1.tar.gz (2.1 kB view details)

Uploaded Source

File details

Details for the file wr-0.1.1.tar.gz.

File metadata

  • Download URL: wr-0.1.1.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 102cc5c6f5ab612829ee18b392729511d811159e407dd6b2632a03542f427136
MD5 8c8c8334336187072200e5a7f41cd964
BLAKE2b-256 02f89aad0cb383bc506eb8e4d11e21b9b891a09dfdb92b7c47b487e527c2fec5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page