Created
May 7, 2020 08:28
-
-
Save ramalho/0c07ef181be433efcdce9c3643b2c38b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import shuffle | |
from typing import Sequence, List, Any | |
def sample(population: Sequence, size: int) -> List: | |
if size < 1: | |
raise ValueError('size must be >= 1') | |
result = list(population) | |
shuffle(result) | |
return result[:size] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment