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.
Created on 2013年07月09日 13:11 by christian.heimes, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| random_choices.patch | christian.heimes, 2013年07月09日 13:11 | review | ||
| Messages (4) | |||
|---|---|---|---|
| msg192747 - (view) | Author: Christian Heimes (christian.heimes) * (Python committer) | Date: 2013年07月09日 13:11 | |
The random module has no method to obvious way to select k elements from a sequence without enforcing unique values in the result set. It's a rather useful feature for salts, randomly generated passwords and other applications. See #18405 The patch implements random.choices(seq, k) -> list |
|||
| msg192781 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年07月09日 23:02 | |
How about [random.choice(seq) for i in range(k)]? Isn't it obvious enough? |
|||
| msg192847 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2013年07月11日 07:21 | |
I concur with Antoine. A list comprehension is the standard, obvious idiom for making a list from repeated function calls. Putting sampling without replacement in its own method makes the operation more opaque than a plain list comprehension (which doesn't need documentation to be clear about how many calls are made, what the output type is, its relationship to random.choice, whether k can be larger than the population, etc). |
|||
| msg192860 - (view) | Author: Christian Heimes (christian.heimes) * (Python committer) | Date: 2013年07月11日 10:23 | |
You have convinced me. It's not worth yet another API method. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:47 | admin | set | github: 62614 |
| 2013年08月31日 09:24:20 | mark.dickinson | link | issue18888 superseder |
| 2013年07月11日 10:23:14 | christian.heimes | set | status: open -> closed resolution: rejected messages: + msg192860 stage: patch review -> resolved |
| 2013年07月11日 07:21:28 | rhettinger | set | messages: + msg192847 |
| 2013年07月09日 23:02:29 | pitrou | set | nosy:
+ pitrou messages: + msg192781 |
| 2013年07月09日 22:05:15 | rhettinger | set | assignee: rhettinger |
| 2013年07月09日 13:11:25 | christian.heimes | create | |