[Tutor] more newbie questions

Lloyd Kvam pythontutor@venix.com
Tue, 30 Apr 2002 16:31:44 -0400


 >>> for row in grid:
... 	print "%s%s%s" % tuple(row)
... 	
123
456
789

Then I had a brain storm for when you don't know the size of the
row:
 >>> for row in grid:
... 	fmt = "%s" * len(row)
... 	print fmt % tuple(row)
... 	
123
456
789

You will need to get a better format if you have digits of differing widths.

Each print after a "print ," will introduce a leading space.


urgrue wrote:

> 
>> You can try <Ctrl+L> in command-line Python on *NIX OSes.
> 
> 
> is there no cross-platform alternative?
> well, i guess print "\n"*24 is fine, its just a bit sloppy.
> 
>> >>> print "this", "is", "a", "test"
>> this is a test
>> >>> print "this" + "is" + "a" + "test"
>> thisisatest
> 
> 
> thanks, thats what i wanted indeed. but, how would this be done for 
> example in this case:
> grid = [[1,2,3],[4,5,6],[7,8,9]]
> for row in grid:
>         for column in row:
>                 print column,
>         print
> 
> now this does:
> 1 2 3
> 4 5 6
> 7 8 9
> but i need:
> 123
> 456
> 789
> 
> thanks,
> fred
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582