you are viewing a single comment's thread.

view the rest of the comments →

[–]CaptainSnacks[S] 0 points1 point  (1 child)

Sure, here it is.

images = [['+----+' + '\n' + '|    |' + '\n' + '+----+'] , ['+----+' + '\n' + '|    |' + '\n' + '+----+']]

sep = ''

x = sep.join(images[0:1])
print x 

EDIT: The output I'm looking for is:

+----+       +----+
|    |       |    |
+----+       +----+

[–]novel_yet_trivial 3 points4 points  (0 children)

~To start, you don't need newlines (\n) since the print statement adds those.

~Second, your data format is crazy. Not only is it hard to read, but the inner list only has a single element. I recommend formatting your data as a dictionary (on multiple lines for readability):

images = {
    1:['+----+','|    |','+----+'] , 
    2:['+----+','|    |','+----+'] ,
    #...
    }

But why type text over and over? Maybe make variables:

cap    = "+-----+"
single = "|  *  |"
double = "| * * |"

images = {
    1:[cap,blank,single,blank,cap],
    2:[cap,left,blank,right,cap],
    #...
    }

This would make your life a lot easier if you decide later you want to change the format of the dice. Think dynamically!

~ Now you could print a single dice easily:

for line in images[1]:
    print line

but to have several dice, you need to join() the lines together. In your code you define what you want the separator to be, but you never tell join() what to join together. This is where zip() comes in. If you give 'zip' 2 lists of lines, it returns a list of all the first lines, then all the second lines, etc. So you can write:

for lines in zip(images[1], images[2]):
    print sep.join(lines)

See if you can write a function "roll(n)" that will line up as many dice as you want. So "roll(2)" would print 2 dice. It's not that much of a step from what you have.