I need to make all possible combinations of any length of list items without using itertools.
Example: list = [1,2,3]
Output: [[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]] ( not necessarily in lexicographical order)
I have this code:
def get_combination(list_of_ palindrome):
res = [list_of_palindrome[i: j] for i in the range (len(list_of_palindrome)) for j in the range (i + 1, len(list_of_palindrome) + 1)]
return res
Output: [[1], [1, 2], [1, 2, 3], [2], [2, 3], [3]]