Python将权重添加到随机样本

时间:2018-08-30 07:51:29

标签: python python-3.x discord discord.py

如何在以下代码中添加权重。例如:如果我想添加x2 for redx5 for black,那么最终所有颜色将是x1,红色和黑色除外。

colours = {'red', 'blue', 'green', 'yellow', 'black', 'purple',
           'Brown', 'Orange', 'violet', 'gray'}

@bot.command(pass_context=True)  
async def pick(ctx):
  colours_copy = colours.copy()
  for n in [1, 2, 3]:
      cs = random.sample(colours_copy , k=n)
      colours_copy -= set(cs)
      await bot.send_message(ctx.message.channel, "{}\n".format(", ".join(cs)))

0 个答案:

没有答案