Example 1,
Input: [a,b,c,d]
Output: [[a],[a,b],[b,c],[c,d],[a,b,c],[b,c,d],[a,b,c,d]]
Example 2,
Input: [1,2,3,4,5]
Output: [[1],[1,2],[2,3],[3,4],[4,5],[1,2,3],[2,3,4],[3,4,5],[1,2,3,4],[2,3,4,5],[1,2,3,4,5]]
In the same way, the number of elements in the pair starting from 1 increases till 'n'(size of the given list)
Is there a possible way of handling, a given list of any size (If possible in Python)
Extra Info:
I have tried this code, which returns pair of 3 elements in the output but I want to return first 1 element, next with 2 elements, till n-1 elements as I mentioned above in the example
Input:
listA = [51,23,11,45]
res = [[listA[i], listA[i + 1],listA[i + 2]] for i in range(len(listA) - 2)]
print("List with paired elements: \n",res)
Output:
List with paired elements: [[51, 23, 11], [23, 11, 45]]