In python 2 you do not combine "range functions"; these are just lists. Your example works well. But a range always creates a complete list in memory, so the best way, if only needed for a loop, is to use a generator expression and xrange:
range_with_holes = (j for j in xrange(1, 31) if j != 6) for i in range_with_holes: ....
In the generator expression, the if part may contain complex logic by which the missing numbers.
Another way to combine iterations is to use itertools.chain :
range_with_holes = itertools.chain(xrange(1, 6), xrange(7, 31))
Or just skip the unwanted index
for i in range(1, 31): if i == 6: continue ...
source share