view misc/choice/question.rst @ 0:20fea762903e

Import some exercises and solutions
author Louis Opter <kalessin@kalessin.fr>
date Sat, 29 Jun 2013 19:30:31 -0700
parents
children
line wrap: on
line source

“Random” Choice
===============

Write a function that takes a list of weighted values and returns a random
value according to its weigh:

.. code-block:: python

   # → 1/2 chances of returning c, 1/3 b, 1/6 a (saying this should help)
   choice([("a", 1), ("b", 2), ("c", 3)])