This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: small mistake in example for random.choice()
Type: Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Anton Tagunov, docs@python, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-10-27 13:52 by Anton Tagunov, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg253537 - (view) Author: Anton Tagunov (Anton Tagunov) Date: 2015-10-27 13:52
Invalid example at this page: https://docs.python.org/3.6/library/random.html

'.items()' is missed in the line below:

>>> population = [val for val, cnt in weighted_choices for i in range(cnt)]


The correct variant:

>>> population = [val for val, cnt in weighted_choices.items() for i in range(cnt)]
msg253548 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-10-27 15:55
There is no mistake. weighted_choices is a list of pairs.
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69676
2015-10-27 15:55:50serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg253548

resolution: not a bug
stage: resolved
2015-10-27 13:52:10Anton Tagunovcreate