Use itertools.chain
:
import itertools
a = range(1,6)
b = range(7,31)
for i in itertools.chain(a, b):
print i
Or tricky flattening generator expressions:
a = range(1,6)
b = range(7,31)
for i in (x for y in (a, b) for x in y):
print i
Or skipping in a generator expression:
skips = set((6,))
for i in (x for x in range(1, 31) if x not in skips):
print i
Any of these will work for any iterable(s), not just range
s in Python 3 or lists
s in Python 2.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…