我正在尝试将 playerdeck
列表中 cards
列表中的单词分配给一个变量。这是我尝试使用的代码,但它返回 False
。
playerdeck = ['Five of Spades', 'Eight of Spades',
'Eight of Clubs', 'Four of Clubs', 'Ace of Spades',
'Eight of Hearts', 'Four of Diamonds']
cards = ['King', 'Queen', 'Jack', 'Ace',
'Two', 'Three', 'Four', 'Five',
'Six', 'Seven', 'Eight', 'Nine',
'Ten']
new = cards in playerdeck
print(new)
有人可以帮忙吗?
最佳答案
你可以试试:
>>> playerdeck = ['Five of Spades', 'Eight of Spades',
'Eight of Clubs', 'Four of Clubs', 'Ace of Spades',
'Eight of Hearts', 'Four of Diamonds']
>>> cards = ['King', 'Queen', 'Jack', 'Ace',
'Two', 'Three', 'Four', 'Five',
'Six', 'Seven', 'Eight', 'Nine',
'Ten']
>>>
>>> for pd in playerdeck:
temp = pd.split(" ")
for data in temp:
if data in cards:
print data
Five
Eight
Eight
Four
Ace
Eight
Four
关于python - 仅将列表中的某些单词分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42618950/