alecxe alecxe - 2 months ago 17
Python Question

Random sampling with Hypothesis

In Hypothesis, there is an corresponding

strategy to
random.choice()
:

In [1]: from hypothesis import find, strategies as st

In [2]: find(st.sampled_from(('ST', 'LT', 'TG', 'CT')), lambda x: True)
Out[2]: 'ST'


But, is there a way to have
random.sample()
-like strategy to produce subsequences of length N out of a sequence?

In [3]: import random

In [4]: random.sample(('ST', 'LT', 'TG', 'CT'), 2)
Out[4]: ['CT', 'TG']

Answer

You could do:

permutations(elements).map(lambda x: x[:n])