First of all, all possible combinations of a list should be generated. It is straightforward problem - thanks to itertools.combinations. Then, the combinations must be ordered according to the following priorities: first element of the original list has the highest priority, second has the second priority and so on. Note that any grouping of lower priorities cannot be higher than any higher priority. Trivial example:
input = ['A', 'B']
output = [['A', 'B'], ['A'], ['B']]
3 elements example:
input = ['A', 'B', 'C']
output = [['A', 'B', 'C'], ['A', 'B'], ['A', 'C'], ['A'], ['B', 'C'], ['B'], ['C']]
Question: Given a list of any elements, how to find the list of all possible combinations ordered by priorities as described above?