在假设中,有一个 corresponding sampled_from()
strategy至 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'
但是,有没有办法让random.sample()
-从序列中生成长度为 N 的子序列的类似策略?
In [3]: import random
In [4]: random.sample(('ST', 'LT', 'TG', 'CT'), 2)
Out[4]: ['CT', 'TG']
最佳答案
你可以这样做:
permutations(elements).map(lambda x: x[:n])
关于python - 假设随机抽样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39670903/