I encounter a problem in Python: Given a list of n elements, I would like to find all the "connected" element combination in the list.
For example, given list = ['a', 'b', 'c']
, I would like to find
['a', 'b', 'c']
['ab', 'c']
['a', 'bc']
['abc']
Similarly, given list = ['a', 'b', 'c', 'd']
, I would like to find
['a', 'b', 'c', 'd']
['a', 'bc', 'd']
['a', 'b', 'cd']
['a', 'bcd']
['ab', 'c','d']
['ab', 'cd']
['abc', 'd']
['abcd']
Given a list of n elements, there will be 2^(n-1) combinations. May I ask whether there is any hint to help me with this? Shall I use recursion?