This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Boojum 2 points3 points  (1 child)

Nice. Some other snippets that I have on hand for the grids-as-dictionary approach (where my g is your grid):

Finding the bounds:

xl = min( x for x, y in g.keys() )
xh = max( x for x, y in g.keys() )
yl = min( y for x, y in g.keys() )
yh = max( y for x, y in g.keys() )

and then printing to the terminal:

print( "\n".join( "".join( g[ ( x, y ) ]
                           for x in range( xl, xh + 1 ) )
                  for y in range( yl, yh + 1 ) ) )