我是Python的新手,正在制作纸牌游戏。这个问题对很多人来说可能很容易。
dealerCom = []
for subset in combinations(dealer_deck, 4) :
dealerCom.append(str(dealer_card) + str(subset))
for hands in dealerCom :
hands.replace(',', '')
print(dealerCom[1819])
print(dealerCom[1819].replace(',', '') )
第一个打印语句返回KC(9D,5H,AH,TD) 第二个打印语句正确返回KC(9D 5H AH TD)
尝试使用第二个for循环格式化,但是里面似乎没有任何作用。但是,第二个打印语句确实以某种方式格式化。
- Dealer_card是物件清单[val = KC]
- Dealer_deck是一个对象列表,我们正在寻找[val = TS 9S 8C 5D AC JH 7D QC KH 6S JD 2S 9D 5H AH TD]的组合
- 目标是最终使用AB CD EF GH单空格格式将DealerCom列表复制到.txt文件中,仅在1820条单独的行上提供数据
- str()转换似乎很奇怪,我进行了很多调试,这是唯一帮助我实际打印DealerCom的东西。[1819]
the problem in the
for
loop is thereplace()
.replace()
does not change the string it is called on, but returns a copy of this string with the desired changes. change your code to look like this: