感谢您阅读本文!
所以这里翻牌圈=三张牌的名单 list_of_players是一个列表,每个索引都有两张卡
我的代码试图将三张翻牌添加到list_of_players的每个索引中,以便每个索引代表翻牌后翻牌手
from pokerset import poker_hand, deck
working_deck = deck()
list_of_players = [6]
number_of_players = len(list_of_players)
cards=2
flop = []
for i in range(3):
flop.append(working_deck.get_card())
list_of_players = [[working_deck.get_card() for i in range(2)] for i in range(6)]
print list_of_players
print flop
for i in range(6):
list_of_players[i].append(flop[i] for i in range(3))
print list_of_players
但是当我打印播放列表时输出是
[[4-Diamonds, 3-Diamonds, <generator object <genexpr> at 0x102125780>], [10-Clubs, 10-Hearts, <generator object <genexpr> at 0x102125820>], [Queen-Hearts, 2-Diamonds, <generator object <genexpr> at 0x102125870>], [Jack-Diamonds, 2-Spades, <generator object <genexpr> at 0x1021258c0>], [Ace-Clubs, Ace-Spades, <generator object <genexpr> at 0x102125910>], [3-Spades, 7-Spades, <generator object <genexpr> at 0x102125960>]]
[以0.0s结束]
对此的解释超出了我的理解,有人可以从我那里得到一些业力并作为回报给我一些建议吗?
先谢谢你们
答案 0 :(得分:1)
在for
循环中,flop[i] for i in range(3)
是generator expression。您将该生成器放在循环的末尾,它显示为<generator object <genexpr> at 0x102125780>
之类的东西。你想要的是追加生成器产生的每个值。为此,请使用.extend()
:
for i in range(6):
list_of_players[i].extend(flop[i] for i in range(3))
答案 1 :(得分:0)
首先改变
list_of_players = [6]
到
list_of_players = [0]*6
因为那条线看起来不太好。
在你的上一个for循环中,你应该尝试这个
for i in range(6):
list_of_players[i].append([flop[i] for i in range(3)])
当你没有放置&#39; []&#39;在你的理解表达式周围,它创建了一个生成器表达式而不是列表。 我希望这会有所帮助。