def spanningsets(items):
    if not items:
        return
if len(items) == 1:
    yield [[items[-1]]]
else:
    for cc in spanningsets(items[:-1]):
        yield cc + [[items[-1]]]
for i in range(len(cc)):
    yield cc[:i] + [cc[i] + [items[-1]]] + cc[i + 1:]
for sset in spanningsets([1, 2, 3, 4]):
    pass
Algorithm to generate spanning set