3

I am trying a problem to make Graphical designs in Python, more specifically ASCII "banner" words. Each letter is made up of a nested list of lines of the character.

 [[' _______ ', '(       )', '| () () |', '| || || |', '| |(_)| |', '| |   | |', '| )   ( |', '|/     \\|'], [' _______ ', '(  ____ \\', '| (    \\/', '| (__    ', '|  __)   ', '| (      ', '| (____/\\', '(_______/']]

etc.

When printed down for each nested list and across for the whole thing, they make a word. I am having trouble printing it as I said above, down for each nested list and across for the whole thing. Thanks in advance!

The6thSense
  • 8,103
  • 8
  • 31
  • 65

2 Answers2

9

If you want to print the letters from left to right, you will have to zip the list of lists with itself, effectively "transposing" it. This way, the first list will have all the first rows, the second list all the second rows, and so on. Now just join those and you are done.

>>> ascii = [[' _______ ', '(       )', '| () () |', '| || || |', '| |(_)| |', '| |   | |', '| )   ( |', '|/     \\|'], [' _______ ', '(  ____ \\', '| (    \\/', '| (__    ', '|  __)   ', '| (      ', '| (____/\\', '(_______/']]
>>> print '\n'.join((' '.join(line) for line in zip(*ascii))) 
 _______   _______ 
(       ) (  ____ \
| () () | | (    \/
| || || | | (__    
| |(_)| | |  __)   
| |   | | | (      
| )   ( | | (____/\
|/     \| (_______/

And if you want to print the letters from top to bottom, you can use this:

>>> print '\n\n'.join(('\n'.join(line) for line in ascii))
Community
  • 1
  • 1
tobias_k
  • 81,265
  • 12
  • 120
  • 179
2

Although it's not exactly clear what output you want, I believe you could benefit from using the string.join() function.

EDIT

Aha, it's now clear what you are trying to do. Using the solution of @tobias_k I would suggest that you make it easy to edit your letters by doing something like this:

m = """
 _______  
(       ) 
| () () | 
| || || | 
| |(_)| | 
| |   | | 
| )   ( | 
|/     \| 
""".split('\n')

e = """
 _______  
(  ____ \ 
| (    \/ 
| (__     
|  __)    
| (       
| (____/\ 
(_______/ 
""".split('\n')

lines = zip(m,e,m,e)   # Spell the word you want here
print '\n'.join(' '.join(line) for line in lines)

Gives output:

 _______    _______    _______    _______  
(       )  (  ____ \  (       )  (  ____ \ 
| () () |  | (    \/  | () () |  | (    \/ 
| || || |  | (__      | || || |  | (__     
| |(_)| |  |  __)     | |(_)| |  |  __)    
| |   | |  | (        | |   | |  | (       
| )   ( |  | (____/\  | )   ( |  | (____/\ 
|/     \|  (_______/  |/     \|  (_______/ 
Thane Plummer
  • 7,966
  • 3
  • 26
  • 30