python - 假设随机抽样

标签 python unit-testing testing random python-hypothesis

在假设中,有一个 corresponding sampled_from() strategyrandom.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/

相关文章:

python - 如何在 celery 任务中锁定变量?

python - yfinance json.decoder.JSONDecodeError

python - 如何叠加 Pandas 图、matplotlib 图和轴

python - 来自 Django 测试的错误 404?

java - Pact 契约(Contract)测试入门的先决条件

r - 测试 R 包时可以访问外部文件吗?

python - 创建交互变量的函数 : what is wrong with the code?

c# - 如何使用 Nunit 断言每个集合项

ruby-on-rails - rails capybara - 如何检测 js 点击 li(不是链接或按钮)

c# - 在不创建单独项目的情况下使用 Nunit