![]() |
VOOZH | about |
Given a list with some elements being a list of optional elements. The task is to find all the possible combinations from all options.
Examples:
Input: test_list = [1,2,3]
Output:
[1], [1, 2], [1, 2, 3], [1, 3]
[2], [2, 3], [3]
Output:
Combination 1 : ('GFG', [5, 4])
Combination 2 : ('GFG', 'is')
Combination 3 : ('GFG', ['best', 'good', 'better', 'average'])
Combination 4 : ([5, 4], 'is')
Combination 5 : ([5, 4], ['best', 'good', 'better', 'average'])
Combination 6 : ('is', ['best', 'good', 'better', 'average'])Output:
Combination 1 : ('GFG', 'GFG')
Combination 2 : ('GFG', [5, 4])
Combination 3 : ('GFG', 'is')
Combination 4 : ('GFG', ['best', 'good', 'better', 'average'])
Combination 5 : ([5, 4], [5, 4])
Combination 6 : ([5, 4], 'is')
Combination 7 : ([5, 4], ['best', 'good', 'better', 'average'])
Combination 8 : ('is', 'is')
Combination 9 : ('is', ['best', 'good', 'better', 'average'])
Combination 10 : (['best', 'good', 'better', 'average'], ['best', 'good', 'better', 'average'])In this, we use a nested loop to get index wise combinations from each nested option list, and then the outer loop is used to get default values in all combinations.
Output:
(2, 3) (2, 1) (2, 6) (2, 4) (2, 7) (3, 1) (3, 6) (3, 4) (3, 7) (1, 6) (1, 4) (1, 7) (6, 4) (6, 7) (4, 7)
Output:
(2, 3) (2, 1) (2, 6) (2, 4) (2, 7) (3, 1) (3, 6) (3, 4) (3, 7) (1, 6) (1, 4) (1, 7) (6, 4) (6, 7) (4, 7)