You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 bpo-18405
The patch implements random.choices(seq, k) -> list
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).
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: