Easy. Use itertools.combinations() :
from itertools import combinations atom = list('abc') combs = [i for j in range(1, len(atom) + 1) for i in combinations(atom, j)]
which gives:
[('a',), ('b',), ('c',), ('a', 'b'), ('a', 'c'), ('b', 'c'), ('a', 'b', 'c')]
Joel cornett
source share