【发布时间】:2018-03-10 00:17:59
【问题描述】:
我有两张单子,号码基本一样:
import random
A = [ 0, 10, 20, 30, 40 ]
B = [ 0, 10, 20, 30, 40 ]
drawA =(random.choice(A))
drawB =(random.choice(B)) # want to exclude the number drawn in drawA
如果drawB == drawA,如何让python重新绘制。
否则,我如何从列表 B 中提取一个数字,不包括列表 A 中已绘制的数字?
【问题讨论】:
-
A和B总是一样吗? -
为什么不直接使用
random.shuffle,后跟list.pop?或者,drawA, drawB = random.sample(A, 2)。 -
@PeterWood:只有在
A == B时才有效。 -
@EricDuminil
A和B相同,OP 没有另外澄清。
标签: python random while-loop draw