def permutations(lot):
    source = []
cnum = 1
for item, start, end in lot:
    source += [item] * (end - start + 1)
cnum *= end - start + 1
for i in range(cnum):
    bitmask = [True] * len(source)
state = i
pos = 0
for _, start, end in lot:
    state, m = divmod(state, end - start + 1)
pos += end - start + 1
bitmask[pos - m:pos] = [None] * m
yield [(bitmask[i] and c) for i, c in enumerate(source)]
More elegant way to implement regexp-like quantifiers