Hi,
How can I print this figure if I have an array like this?
It should be a for-loop but don´t know how.

labyrinth = \
[[0,0,0,0,0,0,1,0],
[0,1,0,1,1,1,1,0],
[0,1,1,1,0,1,0,0],
[0,1,0,0,0,0,0,0],
[0,1,1,0,1,1,1,0],
[0,0,1,1,1,0,0,0],
[0,1,1,0,1,1,1,0],
[0,1,0,0,0,0,0,0]]

figure:
############. ##
## ##. . . . ##
##. . . ## ####
##. ############
##. . ## ##
####. ######
##. . ## ##
##. ############

from __future__ import print_function # 

labyrinth = \
[[0,0,0,0,0,0,1,0],
[0,1,0,1,1,1,1,0],
[0,1,1,1,0,1,0,0],
[0,1,0,0,0,0,0,0],
[0,1,1,0,1,1,1,0],
[0,0,1,1,1,0,0,0],
[0,1,1,0,1,1,1,0],
[0,1,0,0,0,0,0,0]]

[[print("##" if char==0 else ".",end="" if i<len(line)-1 else "\n") for i,char in enumerate(line)]  for line in labyrinth]

Edited 6 Years Ago by slate: n/a

Wooo Slate and tonyjv are really complex

Infact the pseudo of slate is flawless but will a newbie understand the algos.?

I just wrote this as a step by step to the solution. I real life, i advice you to use Slate's example.

labyrinth = \
[[0,0,0,0,0,0,1,0],
[0,1,0,1,1,1,1,0],
[0,1,1,1,0,1,0,0],
[0,1,0,0,0,0,0,0],
[0,1,1,0,1,1,1,0],
[0,0,1,1,1,0,0,0],
[0,1,1,0,1,1,1,0],
[0,1,0,0,0,0,0,0]]

de=0
for x in labyrinth:
	for y in x:
		de=de+1
		if y == 0:
			print '##',
		else:
			print ".",
		if de == 8:
			print '\n'
			de=0

for fun ;)

Edited 6 Years Ago by richieking: n/a

We are not supposed to give ready answers. After this your try I must write cleaner version, though. Use 4 space tabs next time.
I prefer not to use line continuation character, but utilize automatic continuation inside parenthesis and brackets:

from __future__ import print_function

labyrinth = [
             [0,0,0,0,0,0,1,0],
             [0,1,0,1,1,1,1,0],
             [0,1,1,1,0,1,0,0],
             [0,1,0,0,0,0,0,0],
             [0,1,1,0,1,1,1,0],
             [0,0,1,1,1,0,0,0],
             [0,1,1,0,1,1,1,0],
             [0,1,0,0,0,0,0,0]]

for line in labyrinth:
    for isopen in line:
        print('  ' if isopen else "##", end='')
    print()
print('-'*40)

# in real life
print('\n'.join(''.join('  ' if isopen else "##" for isopen in line)
                        for line in labyrinth))

Edited 6 Years Ago by pyTony: n/a

but tonyjv there is a problem now, if you look at the figure there are some dots, how can I print them just like the figure?

The codes are not there, you maybe must apply one labyrinth solver algorith to find the path, like mine, which solved the labyrinth and when I set the marking of path properly, and gave open places as S and E gave results like this:

The solved labyrinth
############ .##
##  ## .......##
## .....##  ####
## .############
## .. ##      ##
####.     ######
## .. ##      ##
## .############


7.820 ms
Enter to finish

Edited 6 Years Ago by pyTony: n/a

This question has already been answered. Start a new discussion instead.