列表列表,我似乎无法正确缩进
list of lists and i can't seem to get the indent right
现在没有缩进错误:
def best_wild_hand(hand):
#Try all values for jokers in all 5-card selections.
blackJoker= "?B"
redJoker = "?R"
dictSuit = {'2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14 }
listofLists = []
if blackJoker in hand:
newHand = hand.remove(blackJoker)
for d in dictSuit:
listofLists.append(newHand.append(d + "S"))
return listofLists
我正在尝试获取列表列表,如果在传递给 best_wild_hand 方法的手参数列表中找到 blackJoker。如果发现黑色手牌,我们将其移除并将 2..13 + C(一副牌中找到的所有三叶草牌)附加到手牌上。我正在尝试制作一个手牌列表,其中包括 1 个三叶草(因此手牌列表 + nC)n 是一个数字 2- 13
我的预期输出是列表列表,每个列表中有 2C...13C 替换黑扑克
没有更多错误但是当我 运行 在此打印语句代码中没有 return 任何错误
print best_wild_hand(['6C', '7C', '8C', '9C', 'TC', '5C', '?B'])
编辑以匹配您的编辑
您的问题是您正在将变量分配给方法。这导致变量为 None
:
>>> y = ['6C'].remove('6C')
>>> print y
None
>>>
改为更改
newHand = hand.remove(blackJoker)
到
newHand = hand
newHand.remove(blackJoker)
因此:
def best_wild_hand(hand):
#Try all values for jokers in all 5-card selections.
blackJoker= "?B"
redJoker = "?R"
dictSuit = {'2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14 }
listofLists = []
if blackJoker in hand:
newHand = hand
newHand.remove(blackJoker)
for d in dictSuit:
listofLists.append(newHand.append(d + "S"))
return listofLists
现在当我运行你的代码时:
bash-3.2$ python safd.py
[None, None, None, None, None, None, None, None, None, None, None, None, None]
bash-3.2$
也许不是你想要的,但它仍然在打印
现在没有缩进错误:
def best_wild_hand(hand):
#Try all values for jokers in all 5-card selections.
blackJoker= "?B"
redJoker = "?R"
dictSuit = {'2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14 }
listofLists = []
if blackJoker in hand:
newHand = hand.remove(blackJoker)
for d in dictSuit:
listofLists.append(newHand.append(d + "S"))
return listofLists
我正在尝试获取列表列表,如果在传递给 best_wild_hand 方法的手参数列表中找到 blackJoker。如果发现黑色手牌,我们将其移除并将 2..13 + C(一副牌中找到的所有三叶草牌)附加到手牌上。我正在尝试制作一个手牌列表,其中包括 1 个三叶草(因此手牌列表 + nC)n 是一个数字 2- 13
我的预期输出是列表列表,每个列表中有 2C...13C 替换黑扑克
没有更多错误但是当我 运行 在此打印语句代码中没有 return 任何错误
print best_wild_hand(['6C', '7C', '8C', '9C', 'TC', '5C', '?B'])
编辑以匹配您的编辑
您的问题是您正在将变量分配给方法。这导致变量为 None
:
>>> y = ['6C'].remove('6C')
>>> print y
None
>>>
改为更改
newHand = hand.remove(blackJoker)
到
newHand = hand
newHand.remove(blackJoker)
因此:
def best_wild_hand(hand):
#Try all values for jokers in all 5-card selections.
blackJoker= "?B"
redJoker = "?R"
dictSuit = {'2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14 }
listofLists = []
if blackJoker in hand:
newHand = hand
newHand.remove(blackJoker)
for d in dictSuit:
listofLists.append(newHand.append(d + "S"))
return listofLists
现在当我运行你的代码时:
bash-3.2$ python safd.py
[None, None, None, None, None, None, None, None, None, None, None, None, None]
bash-3.2$
也许不是你想要的,但它仍然在打印