gpt4 book ai didi

python - 仅将列表中的某些单词分配给变量

转载 作者:太空宇宙 更新时间:2023-11-04 05:12:37 24 4
gpt4 key购买 nike

我正在尝试将 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com