My problem is that I have a text file which contains this:
♦J
♣J
♠J
♣8
♦A
♥9
♥J
♥J
♦A
♦K
♦7
♦J
♦7
♦A
♦K
♥7
♣10
♣J
♠A
♦A
♣J
♦7
♠10
♥K
♣9
♥10
♦A
♠8
♠J
♥9
♦8
♠A
And I am trying to append this in to 8 different lists in order from to bottom. I have 8 different lists and a list that contains all the different lists they are set like this:
deckOne = []
deckTwo = []
DeckThree = []
DeckFour = []
deckFive = []
deckSix = []
deckSeven = []
deckEight = []
deckList = [deckOne, deckTwo, DeckThree, DeckFour, deckFive, deckSix, deckSeven, deckEight]
I get no errors when I run the program, but, I do not get the output that I am expecting. the expected output would look like this:
[♦J, ♣J, ♠J, ♣8]
[♦A, ♥9, ♥J, ♥J]
[♦A, ♦K, ♦7, ♦J]
[♦7, ♦A, ♦K, ♥7]
[♣10, ♣J, ♠A, ♦A]
[♣J, ♦7, ♠10, ♥K]
[♣9, ♥10, ♦A, ♠8]
[♠J, ♥9, ♦8, ♠A]
But the result I am getting is currently this:
[['♦J', '♦A', '♣10', '♣9'], ['♣J', '♦K', '♣J', '♥10'], ['♠J', '♦7', '♠A', '♦A'], ['♣8', '♦J', '♦A', '♠8'], ['♦A', '♦7', '♣J', '♠J'], ['♥9', '♦A', '♦7', '♥9'], ['♥J', '♦K', '♠10', '♦8'], ['♥J', '♥7', '♥K', '♠A']]
This output is wrong is because it appends every 4 lines in the file instead of 4 lines to one list, then the next 4 to the next list, and so on. the code I am trying to use to do this, is this:
def hentLagretSpill():
import codecs
with codecs.open("game_save.txt", 'rb', encoding="utf-8") as gameGetter:
count = 0
for i, l in enumerate(gameGetter):
count += 1
deckList[i % 8].append(l.strip())
print(deckList)
But I have also tried this, and it works, but it is very lengthy:
x = -1
for line in gameGetter:
x += 1
if x // 4 == 0:
deckOne.append(line.strip('\n'))
if x // 4 == 1:
deckTwo.append(line.strip('\n'))
if x // 4 == 2:
DeckThree.append(line.strip('\n'))
if x // 4 == 3:
DeckFour.append(line.strip('\n'))
if x // 4 == 4:
deckFive.append(line.strip('\n'))
if x // 4 == 5:
deckSix.append(line.strip('\n'))
if x // 4 == 6:
deckSeven.append(line.strip('\n'))
if x // 4 == 7:
deckEight.append(line.strip('\n'))
How would I solve this?