79578716

Date: 2025-04-17 07:35:47
Score: 1
Natty:
Report link

Like user2357112's, but fixing the end element is simpler:

import collections
import itertools

def restricted_combinations(elements, sublist_length, combination_length):
    pool = collections.deque(maxlen=sublist_length-1)
    for elem in elements:
        for head in itertools.combinations(pool, combination_length - 1):
            yield (*head, elem)
        pool.append(elem)

Attempt This Online! (includes testing)

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Robert