Reading a matrix from a text file in Python [duplicate] - python

This question already has answers here:
How to to read a matrix from a given file?
(8 answers)
Closed 3 years ago.
I'm trying to read a matrix from a given text file, put it in a dictionary and manipulate it later, however when I try to access the elements, "," shows as an element and it's really messing up my indexing
I've tried to use the split function and it seems to be reading it nicely, but ',' still appears as an element
def loadboard():
f = open("game.txt", "r")
A=f.readline()
B=f.readline()
C=f.readline()
board=[]
board = [[int(num) for num in line.split(',')] for line in f]
print(board)
game = {
"player1" : A,
"player2" :B,
"who" : C,
"board" : board
}
f.close()
return(game)
this is my text file
A
B
C
0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0
0,0,1,2,1,0,0,0
0,0,1,2,2,2,0,0
0,0,1,2,1,0,0,0
0,0,0,2,1,0,0,0
0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0
this is what I see when i print the board
Out[242]:
['0,0,0,0,0,0,0,0\n',
'0,0,0,0,0,0,0,0 \n',
'0,0,1,2,1,0,0,0 \n',
'0,0,1,2,2,2,0,0\n',
'0,0,1,2,1,0,0,0 \n',
'0,0,0,2,1,0,0,0\n',
'0,0,0,0,0,0,0,0\n',
'0,0,0,0,0,0,0,0']
when i try to access the second element which should be a zero again, i get ','
board[0][1]
Out[243]: ','

This work well for me:
board = []
with open('toto.txt', 'r') as f:
for row in f.read().strip().split("\n")[3:]:
board.append(row.split(","))
for line in board:
print (line)
print "board[0] : " + str(board[0])
print "board[0][1] : " + str(board[0][1])
Output:
(venv) C:\Users\hlupo\Documents\SoTest>python test.py
['0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '1', '2', '1', '0', '0', '0']
['0', '0', '1', '2', '2', '2', '0', '0']
['0', '0', '1', '2', '1', '0', '0', '0']
['0', '0', '0', '2', '1', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0']
board[0] : ['0', '0', '0', '0', '0', '0', '0', '0']
board[0][1] : 0

Try this:
with open('game.txt', 'r') as f:
l = [[int(num) for num in line.split(',')] for line in f]
print(l)

This will do:
matrix = []
with open('game.txt','r') as f:
for row in f.read().strip().split("\n")[3:]:
matrix.append(row.split(","))
print(matrix)

Related

How to append binary value into an array?

I pull random binary from a source and I am trying to append each binary bytes into an array. However, Python only append each character into the array and not each binary bytes. I tried to search in here and Google and it seems there is no prior example that I could follow. I wonder if anybody know?
I have this list of 16 binary bytes
random_byte_request:
10001100 11001010 11111101 11010100 01101010 01011001 00010000 10111110 01111000 11111010 00100101 01110001 11001001 10001100 10001000 01001011
I create an empty array:
random_byte_array = []
Then I appended each element into the empty array:
for bits in range(len(random_16_bytes)):
random_byte_array.append(random_16_bytes[bits])
print(random_byte_array)
However the result is not as I wanted:
['1', '0', '0', '0', '1', '1', '0', '0', ' ', '1', '1', '0', '0', '1', '0', '1', '0', ' ', '1', '1', '1', '1', '1', '1', '0', '1', ' ', '1', '1', '0', '1', '0', '1', '0', '0', ' ', '0', '1', '1', '0', '1', '0', '1', '0', ' ', '0', '1', '0', '1', '1', '0', '0', '1', ' ', '0', '0', '0', '1', '0', '0', '0', '0', ' ', '1', '0', '1', '1', '1', '1', '1', '0', ' ', '0', '1', '1', '1', '1', '0', '0', '0', ' ', '1', '1', '1', '1', '1', '0', '1', '0', ' ', '0', '0', '1', '0', '0', '1', '0', '1', ' ', '0', '1', '1', '1', '0', '0', '0', '1', ' ', '1', '1', '0', '0', '1', '0', '0', '1', ' ', '1', '0', '0', '0', '1', '1', '0', '0', ' ', '1', '0', '0', '0', '1', '0', '0', '0', ' ', '0', '1', '0', '0', '1', '0', '1', '1', ' ']
Without having a better look at your code and how your data is being generated I believe the option you really want is extend
random_byte_array = []
random_byte_array.extend(['10001100'])
This would need to be altered in a way that meets your specific needs, but this would create a blank array and allows you to add an entire binary to the end of the array. If you provide a little more detail on your code then we could probably get a little closer to what you are looking for.
You can convert the bytes to string using str(random_byte_request). This will add b' at the start and ' at the end. So stripping that using [2:-1]. Split the string with space using .split(' '). If you want string in the list you can just keep x else if you want bytes in the list as well, encode the string using x.encode('utf8')
random_byte_request = b'10001100 11001010 11111101 11010100 01101010 01011001 00010000 10111110 01111000 11111010 00100101 01110001 11001001 10001100 10001000 01001011'
random_byte_array = [x.encode('utf8') for x in str(random_byte_request)[2:-1].split(' ')]
print(random_byte_array)

How to check if row is contained in another row?

The output of the function is to remove all lines (including list1 after the text) whose first n strings are contained in another line.
The code I tried is terribly written and super slow, but I have no other idea about how to do this. Is there an easier and faster way to do this?
The order of each element in the line is important.
list1 = [["0","0","0","0","0"],
["0","0","0","0","0","0"],
["0","0","0","0","0","275"],
["0","0","0","0","0","275","275"],
["0","0","0","0","275"],
["0","0","0","0","275","275"],
["0","0","0","0","275","990"],
["0","0","0","0","275","990","990"],
["0","0","0","0","275","990","2761"],
["0","0","0","0","275","990","2761","2761"],
["0","0","0","0","688"],
["0","0","0","0","688","688"],
["0","0","0","0","688","1940"],
["0","0","0","0","688","1940","1940"],
["0","0","0","0","688","1940","5041"],
["0","0","0","0","688","1940","5041","5041"],
["0","0","0","165","165","165"],
["0","0","0","165","165","165","165"]]
remove_lines = []
index_to_be_removed = []
for x in range(len(list1)):
for y in range(len(list1)):
if len(list1[x]) > len(list1[y]):
c = 0
for i in range(len(list1[y])):
if list1[x][i] == list1[y][i]:
c = c + 1
if c == len(list1[y]):
if list1[x] not in remove_lines:
remove_lines.append(list1[x])
index_to_be_removed.append(x)
for x in range(len(index_to_be_removed)):
print("lines to be removed:", list1[index_to_be_removed[x]])
Output of the lines which we want to remove:
lines to be removed: ['0', '0', '0', '0', '0', '0']
lines to be removed: ['0', '0', '0', '0', '0', '275']
lines to be removed: ['0', '0', '0', '0', '0', '275', '275']
lines to be removed: ['0', '0', '0', '0', '275', '275']
lines to be removed: ['0', '0', '0', '0', '275', '990']
lines to be removed: ['0', '0', '0', '0', '275', '990', '990']
lines to be removed: ['0', '0', '0', '0', '275', '990', '2761']
lines to be removed: ['0', '0', '0', '0', '275', '990', '2761', '2761']
lines to be removed: ['0', '0', '0', '0', '688', '688']
lines to be removed: ['0', '0', '0', '0', '688', '1940']
lines to be removed: ['0', '0', '0', '0', '688', '1940', '1940']
lines to be removed: ['0', '0', '0', '0', '688', '1940', '5041']
lines to be removed: ['0', '0', '0', '0', '688', '1940', '5041', '5041']
lines to be removed: ['0', '0', '0', '165', '165', '165', '165']
this code is expected to be versatile and Fast.
Lists = [["0","0","0","0","0"], ["0","0","0","0","0","0"], ["0","0","0","0","0","275"], ["0","0","0","0","0","275","275"], ["0","0","0","0","275"], ["0","0","0","0","275","275"], ["0","0","0","0","275","990"], ["0","0","0","0","275","990","990"], ["0","0","0","0","275","990","2761"], ["0","0","0","0","275","990","2761","2761"], ["0","0","0","0","688"], ["0","0","0","0","688","688"], ["0","0","0","0","688","1940"], ["0","0","0","0","688","1940","1940"], ["0","0","0","0","688","1940","5041"], ["0","0","0","0","688","1940","5041","5041"], ["0","0","0","165","165","165"], ["0","0","0","165","165","165","165"]]
def Get_Uniques(Lists):
Selected, Rejected = [], []
for List in Lists :
lenL, selected = len(List), True
for ele in Selected:
lenE = len(ele)
if lenE > lenL: continue
if List[:lenE] == ele:
Rejected.append(List)
selected = False
break
if selected: Selected.append(List)
return Selected, Rejected
Selected, Rejected = Get_Uniques(Lists)
print("Selected Lists : ", *Selected, "\nRejected Lists : ", *Rejected, sep="\n")
OUTPUT
Selected Lists :
['0', '0', '0', '0', '0']
['0', '0', '0', '0', '275']
['0', '0', '0', '0', '688']
['0', '0', '0', '165', '165', '165']
Rejected Lists :
['0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '275']
['0', '0', '0', '0', '0', '275', '275']
['0', '0', '0', '0', '275', '275']
['0', '0', '0', '0', '275', '990']
['0', '0', '0', '0', '275', '990', '990']
['0', '0', '0', '0', '275', '990', '2761']
['0', '0', '0', '0', '275', '990', '2761', '2761']
['0', '0', '0', '0', '688', '688']
['0', '0', '0', '0', '688', '1940']
['0', '0', '0', '0', '688', '1940', '1940']
['0', '0', '0', '0', '688', '1940', '5041']
['0', '0', '0', '0', '688', '1940', '5041', '5041']
['0', '0', '0', '165', '165', '165', '165']
Hope this helps!
I would do this through a pairwise comparison while loop. Basically, I first store all pairs of lists, (n lists becomes 0.5*n*(n-1) pairs of lists). Then, one at a time, I look at each pair, find the smaller list, and check if one is contained in the other using delimited-string comparison. Here's the code:
from itertools import combinations
lists = [["0","0","165","165"],...]
pairs = combinations(lists)
for pair in pairs:
smaller = pair[0] if len(pair[0]) <= len(pair[1]) else pair[1]
bigger = pair[1] if smaller == pair[0] else pair[0]
smaller_str = ",".join(smaller)
bigger_str = ",".join(bigger)
if smaller_str in bigger_str and smaller in lists:
lists.remove(smaller)
print(lists)
This ought to leave only those arrays which are not contained in any other arrays. I don't know if it's necessarily more efficient than your algorithm when you break down its component operations, but it's definitely a bit easier to follow.
You could use a dictionary of tuples for the lists that you keep and use it to check the relevant prefix lengths of subsequent lists. This will give results in O(N) time, or more specifically O(NxD) where N is the number of lists and D is the length difference between the largest and smallest list.
keep = dict() # lists to keep (as tuples)
minLen = min(map(len,list1)) # shortest prefix length
for i,L in enumerate(list1):
prefixes = (tuple(L[:n]) for n in range(minLen,len(L)+1))
if not any(sl in keep for sl in prefixes): # check all prefix lengths
keep[tuple(L)]=i # track lists that remain
else:
print("list to remove",L) # list at index i will be dropped
# clean up
list1 = [*map(list,keep)]
Output:
list to remove ['0', '0', '0', '0', '0', '0']
list to remove ['0', '0', '0', '0', '0', '275']
list to remove ['0', '0', '0', '0', '0', '275', '275']
list to remove ['0', '0', '0', '0', '275', '275']
list to remove ['0', '0', '0', '0', '275', '990']
list to remove ['0', '0', '0', '0', '275', '990', '990']
list to remove ['0', '0', '0', '0', '275', '990', '2761']
list to remove ['0', '0', '0', '0', '275', '990', '2761', '2761']
list to remove ['0', '0', '0', '0', '688', '688']
list to remove ['0', '0', '0', '0', '688', '1940']
list to remove ['0', '0', '0', '0', '688', '1940', '1940']
list to remove ['0', '0', '0', '0', '688', '1940', '5041']
list to remove ['0', '0', '0', '0', '688', '1940', '5041', '5041']
list to remove ['0', '0', '0', '165', '165', '165', '165']
print(list1)
[['0', '0', '0', '0', '0'],
['0', '0', '0', '0', '275'],
['0', '0', '0', '0', '688'],
['0', '0', '0', '165', '165', '165']]

append key if matches specific index and keyword?

titleValues = {'Movie 1 (1998)': ['0', '1', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], 'Movie 2 (1994)': ['0', '1', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0']}
categories={'unknown': '0', 'Action': '1', 'Adventure': '2', 'Animation': '3', "Children's": '4', 'Comedy': '5', 'Crime': '6', 'Documentary': '7', 'Drama': '8', 'Fantasy': '9', 'Film-Noir': '10', 'Horror': '11', 'Musical': '12', 'Mystery': '13', 'Romance': '14', 'Sci-Fi': '15', 'Thriller': '16', 'War': '17', 'Western': '18'}
selectedCol = 1
titles=[]
for key, value in titleValues.items():
for num in value:
if num == '1':
valIdx = value.index(num)
if valIdx == selectedCol:
titles.append(key)
else:
continue
print(titles)
output:
['Movie 1 (1998)', 'Movie 1 (1998)', 'Movie 2 (1994)', 'Movie 2 (1994)', 'Movie 2 (1994)', 'Movie 2 (1994)']
I think it appears 6 times because of the six '1' occurrences. However, how can I only obtain two names as for both lists '1' appears at index 1.
['Movie 1 (1998)', 'Movie 2 (1994)']
only when titleValues contains a one, put key once in a list:
titles = [k for k,v in zip(titleValues.keys(),titleValues.values()) if '1' in v]
result will be
print(titles)
# ['Movie 1 (1998)', 'Movie 2 (1994)']
Explanation
Create two iterables (keys, values)
print(titleValues.keys())
#dict_keys(['Movie 1 (1998)', 'Movie 2 (1994)'])
print(titleValues.values())
#dict_values([['0', '1', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], ['0', '1', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0']])
zip, is a function to iterate element-wise and simultanouesly over two iterables
print(list(zip(titleValues.keys(),titleValues.values())))
# [('Movie 1 (1998)', ['0', '1', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']), ('Movie 2 (1994)', ['0', '1', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0'])]
in a for-comprehension you can access elements of both iterables (specified variable name: k for element in first iterable and v for element in second)

list position replacement with if statement

Can we perform replace on python list?
I have that list that is imported from csv file:
[['1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], ['2', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0'], ['3', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0']]
fist index(mark as bold) from list above will became costumer id followed by the item that they buy, from list above we can see costumer 1 purchased item in column 12 that marked by italic.
desire out put is :
costumer 1 purchased item 12 and item 22 and so it's for costumer 2 and
3
Note that I have try used panda and not work, and I not sure how to use if statement inside the for loop.
Also, I have used rappid minner and they replaced column by column and they included the [0][0] to be replaced. Is there any other solution beside python?
Here is my code:
import csv
csvfile = open("tran.csv", 'r')
reader = csv.reader(csvfile, delimiter=',')
my_list = list(reader)
a = len(my_list[1])
b = (my_list)
x=0
y=0
for name in my_list:
print ("costummer", my_list[0][0], "buy", my_list[n][g])
update for csv writer:
csvdict = {words[0]:words[1:] for words in csv}
for x in csvdict.keys(): # iterate over the keys '1', '2', ....
products = [index+1 for index,v in enumerate(csvdict[x]) if v == '1' ] # create list of purchases where the '1's are indexed
f = open("trans.csv", 'w')
result = ("costummer", x, "buy", products)
resultstr = (','.join([str(x) for x in hasil]))#I try to convert it to str.
print (resultstr) #to check whether the conversion from list into str is working or not.
f.write(resultstr) #try to write to csv file
Here is a "starting point", there will be an extra index for the customer 1, that is something you can play around with. It might not be important. You can add a if clause to take care of it.
csv = [['1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], ['2', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0'], ['3', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0']]
csvdict = {words[0]:words[1:] for words in csv}
for x in sorted(csvdict.keys()): # iterate over the keys '1', '2', ....
products = [index+1 for index,v in enumerate(csvdict[x]) if v == '1' ] # create list of purchases where the '1's are indexed
print "costummer", x, "purchased", ' '.join(['"item '+str(i)+'"' for i in B])

Having troubles with list

Okey, I'm currently writing Conway's Game of Life and I have reached a point that I don't know how to solve.
Edit here are the different lists I'm having trouble with:
for repeticiones in range(0,5):
nuevo_mapa = mapax
print(mapax)
if '#' in mapax:
print('Jell')
if mapax is mapa_juego:
print('God')
for y in range(0,10):
for x in range(0,10):
if mapa_juego[y][x] == '#':
viva_muerta = True
elif mapa_juego[y][x] == '0':
viva_muerta = False
for i in range(0,8):
try:
if mapa_juego[y + check_listy[i]][x + check_listx[i]] == '#':
sum += 1
except IndexError:
pass
if viva_muerta == True and sum in [0,1]:
nuevo_mapa[y][x] = '0'
elif viva_muerta == True and sum >= 4:
nuevo_mapa[y][x] = '0'
elif viva_muerta == True and sum in [2,3]:
nuevo_mapa[y][x] = '#'
elif viva_muerta == False and sum == 3:
nuevo_mapa[y][x] = '#'
sum = 0
mapa_juego = nuevo_mapa
print('\n\n')
mapax is a list of lists full of 0.
I want to do this:
nuevo_mapa = mapax
nuevo_mapa is modified
mapa_juego = nuevo_mapa
And start over and over again.
But the problem comes here, after the first iteration mapax is no more a full list of 0.
The output is something like this(I want publish it all because it's so messy and to avoid confusions)
>>> [0,0,0,0,0,0,0] First print of mapax
>>> [0,0,#,0,0,0,0] Second print of mapax and I want to avoid this.
If you see anything in the code let me know, thanks.
Edit: here are the different lists I'm having trouble with:
mapa_juego = [
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','#','0','0','0','0','0','0','0',],
['0','0','0','#','0','0','0','0','0','0',],
['0','#','#','#','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',]
]
mapax = [
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',]
]
2 Edit: Here is full code:
mapa_juego = [
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','#','0','0','0','0','0','0','0',],
['0','0','0','#','0','0','0','0','0','0',],
['0','#','#','#','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',]
]
mapax = [
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',],
['0','0','0','0','0','0','0','0','0','0',]
]
viva_muerta = None
check_listy = [0,0,1,-1,-1,1,-1,1]
check_listx = [1,-1,0,0,1,1,-1,-1]
sum = 0
#Reglas
# Una célula muerta con exactamente 3 células vecinas vivas "nace" (es decir, al turno siguiente estará viva).
# Una célula viva con 2 ó 3 células vecinas vivas sigue viva, en otro caso muere o permanece muerta (por "soledad" o "superpoblación").
# Célula viva = True muerta = False
# for line in mapa_juego:
# print(line)
for repeticiones in range(0,5):
nuevo_mapa = mapax
print(mapax)
if '#' in mapax:
print('Jell')
if mapax is mapa_juego:
print('God')
for y in range(0,10):
for x in range(0,10):
if mapa_juego[y][x] == '#':
viva_muerta = True
elif mapa_juego[y][x] == '0':
viva_muerta = False
for i in range(0,8):
try:
if mapa_juego[y + check_listy[i]][x + check_listx[i]] == '#':
sum += 1
except IndexError:
pass
if viva_muerta == True and sum in [0,1]:
nuevo_mapa[y][x] = '0'
elif viva_muerta == True and sum >= 4:
nuevo_mapa[y][x] = '0'
elif viva_muerta == True and sum in [2,3]:
nuevo_mapa[y][x] = '#'
elif viva_muerta == False and sum == 3:
nuevo_mapa[y][x] = '#'
sum = 0
mapa_juego = nuevo_mapa
print('\n\n')
Edit 3: Real output
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '#', '0', '#', '0', '0', '0', '0', '0', '0']
['0', '0', '#', '#', '0', '0', '0', '0', '0', '0']
['0', '0', '#', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
God
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '#', '#', '0', '0', '0', '0', '0', '0']
['0', '#', '0', '#', '0', '0', '0', '0', '0', '0']
['0', '0', '#', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
God
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '#', '#', '0', '0', '0', '0', '0', '0']
['0', '#', '0', '#', '0', '0', '0', '0', '0', '0']
['0', '0', '#', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
God
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '#', '#', '0', '0', '0', '0', '0', '0']
['0', '#', '0', '#', '0', '0', '0', '0', '0', '0']
['0', '0', '#', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
God

Categories

Resources