Skip to main content

sample

Given a list x a sample of length n of that list is returned.

For example, if `n` is 10, and `x` has 100 items, a list of every tenth.
item is returned.

``k`` can be used as offset.
def sample(
x: list,
n: int,
k: int = 0
) - > generator

Given a list x a sample of length n of that list is returned. For example, if n is 10, and x has 100 items, a list of every tenth item is returned. k can be used as offset.

Parameters

NameTypeDescription
xlistThe source list from which elements will be sampled.
nintThe desired number of elements to include in the sample.
kint = 0The starting index offset for the sampling process.

Returns

TypeDescription
generatorA generator yielding items from the list at calculated intervals based on the desired sample size.