Skip to content

Instantly share code, notes, and snippets.

@ramalho
Created May 7, 2020 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramalho/0c07ef181be433efcdce9c3643b2c38b to your computer and use it in GitHub Desktop.
Save ramalho/0c07ef181be433efcdce9c3643b2c38b to your computer and use it in GitHub Desktop.
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