Title: small mistake in example for random.choice()
Type: Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
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 2015-10-27 15:55 by serhiy.storchaka. 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:

'.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.
Date User Action Args
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