I working through a tutorial working on lists and using tic-tac-toe.
I am given a string like: XOXOXOXXO
And I'd like to convert this into a matrix or a list of list, for example:
tic_tac_toe= [[ 'X', 'O', 'X'],
[ 'O', 'X', 'O'],
[ 'O', 'X', 'X']]
I can get this as a 'list', but I can't get this as a list of lists.
I've been searching various posts, and one challenge is I see a lot that are 5 or 7 years old, and I have to wonder how relevant some of the answers still are, and I haven't been able to make work those prior recommendations.
player_actions = 'XO_OOX_X_'
cells = list()
print('Before loop:', player_actions)
for char in player_actions:
cells.insert(0, ''.join(char.split()))
# Output
print('After loop:', cells)
Output example:
Before loop: XOXOXOXXO
After loop: ['O', 'X', 'X', 'O', 'X', 'O', 'O', 'X', 'X']
Goal: [['O', 'X', 'X'],['O', 'X', 'O'],['O', 'X', 'X']]
[['O', 'X', 'X'],['O', 'X', 'O'],['O', 'X', 'X']]doesn't seem to match your input stringXOXOXOXXO