JavaScript
x
4
1
maze = [["|"," ","|"],[" "," "," "],[" ","_","|"],
2
["|"," "," "],[" "," "," "],[" ","_","|"],
3
["|"," ","|"],[" "," "," "],[" ","X","|"]]
4
How do I print the given list in a such a way that the commas ‘,’ and the brackets ‘[]’ are separated, and there is a new line every three elements. I’ve tried the code given below, but it doesn’t work.
JavaScript
1
3
1
for x in maze:
2
print('n'.join(map(int,maze)))
3
I want the output to be like:
JavaScript
1
4
1
| | _|
2
| _|
3
| | |
4
basically, it’s a maze without the upper and lower roofs
At the same time, How should I represent the upper and lover borders of the maze? Thanks
Advertisement
Answer
JavaScript
1
8
1
counter=0
2
for lst in maze:
3
for item in lst:
4
print(item,end="")
5
counter+=1
6
if(counter%3==0):
7
print()
8
or use join method:
JavaScript
1
7
1
counter=0
2
for item in maze:
3
print("".join(item),end="")
4
counter+=1
5
if(counter%3==0):
6
print()
7
have fun :)