我有兩份名單,基本上同一個號碼:蟒蛇再怎麼畫一個變量,如果它是另一個相同的變量
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
重新繪製。
否則,如何從列表B中繪製一個數字,但不包括列表A中已繪製的數字?
總是會有'A'和'B' 是相同的? –
爲什麼不使用'random.shuffle'然後是'list.pop'?或者,'drawA,drawB = random.sample(A,2)'。 –
[**'random.sample' **](https://docs.python.org/2/library/random.html#random.sample)。 –