Need help splicing string objects in a list in Python

Viewed 33

I'm kinda new to Python, and building a card game. This question may be easy for a lot of people.

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(',', '') )

First print statement returns KC ( 9D , 5H , AH , TD ) Second print statement properly returns KC ( 9D 5H AH TD )

Trying to format out using the second for loop, however nothing inside it seems to work. The second print statement does however format somehow.

  1. dealer_card is a object list [val= KC]
  2. dealer_deck is a object list that we are finding combinations of [val= TS 9S 8C 5D AC JH 7D QC KH 6S JD 2S 9D 5H AH TD]
  3. Objective is to copy dealerCom list into a .txt file eventually using AB CD EF GH single space formatting, data only on 1820 individual lines
  4. The str() conversion might seem weird, I was debugging a lot and that's the only thing that helped me actually print dealerCom[1819]
1 Answers

the problem in the for loop is the replace(). 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:

for index in range(len(dealerCom)):
    dealerCom[index] = dealerCom[index].replace(',', '')
Related