Incremental row,column indices
Not sure if this is particularly efficient, but I used the Python modulus operator, '%'. The following code gives a function that produces an iterable object that produces successive row,col pairs. It also shows how to use a couple of lines of code within something - looping through a list, say.
# Creates a series of incremental row and column indices
# Returns and iterable containg tuple of i,j indices
def row_col_idx(r,c):
it = []
for k in range(r*c):
j = (k % c + 1)
i = (int(k/c))%max(r,c) + 1
it.append ((i,j))
#print("r =",i,"c =",j)
return iter(it)
# And here's how it works
fred = row_col_idx(10,4)
for i,j in fred:
print (str(i)+','+str(j))
# Or, more directly:
r=3
c=2
my_list = ['one', 'two', 'three', 'four', 'five', 'six']
for k, numb in enumerate(my_list):
j = (k % c)
i = (int(k/c))%max(r,c)
print (str(i)+','+str(j)+'th numberis: '+numb)