Whats the best way to generate all combinations of a list, where each combinations contains every item from the list and where you can combine other items.
For example, for a list ['a','b','c'], I like to generate:
['a','b','c']
['ab','c']
['a','bc']
['abc']
I find it a bit similar to: Python: Generating all ordered combinations of a list. But this one only cares about the slices. I want all the combinations that takes every item from the list. Is there a built in function from itertools that can be used to generate the answer?
The list could also be numbers, that could have duplicates values. For example: [1,2,1] should generate:
[1,2,1]
[12,1]
[1,21]
[121]
I could try to use the code from the link, but instead of generating combinations of the items, I would generate the combinations base on the index of the list. Where I take all combinations that start with 0, then look for the next item and look for all combinations that start with that item and so on. I dont think that would be efficient though.