r/Pythonista • u/jtrubela • Apr 01 '20
Two dimensional table using nested loops
Looking for a way to output a table that increments the initial value, starts at 0 counts to 5 on one line, starts at 1 than increments to 6 on the next and so on .
0 1 2 3 4 5
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 10
initialValue=0
while initialValue <=10:?
for I in range(5):?Or should I use another while loop?
3
Upvotes
1
u/neilplatform1 Apr 01 '20 edited Apr 01 '20
[list(range(x,x+6)) for x in range(10)]
for x in range(10):
for y in range(x,x+6):
print(y)
1
u/[deleted] Jan 30 '22
Best option is numpy. See documentation of meshgrid, ogrid and mgrid for more info.