python Improve a function in a elegant way
Numpy has built in functions for most simple tasks like this one. In your case, numpy.ndindex should do the trick:

&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; [j for j in np.ndindex(3, 5)]
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4),
 (2, 0), (2, 1), (2, 2), (2, 3), (2, 4)]


You can get the same result in a similarly compact way using itertools.product :

&gt;&gt;&gt; import itertools
&gt;&gt;&gt; [j for j in itertools.product(xrange(3), xrange(5))]
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4),
 (2, 0), (2, 1), (2, 2), (2, 3), (2, 4)]


EDIT Note that the (now corrected) order of the parameters is reversed with respect to the OP's get_IDgrid.

Both expressions above require a list comprehension, because what gets returned is a generator. You may want to consider whether you really need the whole list of index pairs, or if you could consume them one by one.