Printing lists in columns (was: TypeError: 'module object is not callable')

Duncan Booth duncan.booth at invalid.invalid
Tue Sep 4 11:16:54 EDT 2007


cjt22 at bath.ac.uk wrote:

> I know this makes me sound very stupid but how would I specify
> in the parameter the inner lists without having to write them all out
> such as:
> 
> for row in izip_longest(d[0], d[1], d[2], fillvalue='*'):
>     print ', '.join(row)
> 
> i.e. How could I do the following if I didn't know how many list of
> lists I had.
> Sorry this sounds stupid and easy.
> Thankyou very much in advance as well, you are all very helpful
> indeed.

The variable arguments have to appear last in the call (in the order *x, 
**y if you have both):

>>> a = ["1" , "2"];  b = ["4", "5", "6"];  c = ["7", "8", "9"]
>>> d = [a, b, c]
>>> for row in izip_longest(fillvalue='*', *d):
	print ', '.join(row)

	
1, 4, 7
2, 5, 8
*, 6, 9
>>> 



More information about the Python-list mailing list