def nonprefix_combinations(iterable, maxlen):
    iterable = list(iterable)
if not (iterable and maxlen):
    return
for comb in combinations(iterable, maxlen):
    yield comb
for length in range(maxlen - 2, -1, -1):
    for comb in combinations(iterable[:-1], length):
        yield comb + (iterable[-1],)
Efficient enumeration of ordered subsets in Python