[英]How can i select random items from a set of two lists and then remove that set of items from another list built out of all the possibilities
從事紙牌游戲的任務。 我在這里有三個列表,我試圖弄清楚如何確保一張牌如果在一只手中的話不會出現在牌組列表中。
DECK = []
PLAYER = []
COMP = []
for x in PLAYER:
if i,j in PLAYER:
if i,j in DECK:
p = DECK.index(i,j)
p = -51+p
DECK.pop(-p)
我知道i,j在這里不工作。 我怎樣才能代表手中的卡,以便可以將其編入索引並將其從包含卡組的列表中刪除? 我想我可能還不太了解,我現在才學習Python大約四個星期。 提前致謝。
也許:
for x in PLAYER:
if x in DECK:
DECK.remove(x)
您應該將卡片從DECK分發給PLAYER和COMP。 在那種情況下,您將不會陷入這種情況。
就像是:
PLAYER.append(DECK.pop(index))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.