Printing n elements per line in a list
John Machin
sjmachin at lexicon.net
Thu Aug 17 00:11:15 EDT 2006
Matimus wrote:
> Well, I have another at bat, so I will try to redeem myself... using
> recursion:
>
> def printTable(l,c):
> print(("%d "*len(l[:c]))%tuple(l[:c]))
> if( len(l[:c]) > 0 ):
> printTable(l[c:],c)
>
> printTable(range(1,101),5)
Sorry. Recursion disqualified your batter before he got out of the
dugout. Besides the %d restricts it to use wirh integers, and using
"L".lower() as a variable name made the umpire barf through his
facemask all over the catcher. Fortunately the ump didn't notice the
weirdly-spaced and superfluous () in the if statement ...
More information about the Python-list
mailing list