[Tutor] Iterate Suggestion
Alan Gauld
alan.gauld at btinternet.com
Sat Apr 14 19:18:52 CEST 2012
On 14/04/12 16:27, Tom Tucker wrote:
>
> Hello all. Any suggestions how I could easily iterate over a list and
> print the output 3 across (when possible)?
Using the step size argument to range:
L = range(12)
>>> for n in range(0,len(L),3):
... print L[n],L[n+1],L[n+2]
...
0 1 2
3 4 5
6 7 8
9 10 11
>>>
HTH,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list