Jan-25-2023, 02:57 PM
(This post was last modified: Jan-27-2023, 05:39 AM by deanhystad.)
All possible combinations of 30 items does take a while to compute. It is funny that you expect to print the output.
The time for computing the combinations of 20 items is about 2 seconds on my laptop. If the item count is 30, the number of combinations is 1024 times greater, and I would expect it to take about 2048 seconds to compute.
from itertools import combinations items = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')[:4] combos = sum([list(map(list, combinations(items, i+1))) for i in range(len(items))], []) if len(combos) < 30: print(combos) else: print(len(items), len(combos))
Output:[['A'], ['B'], ['C'], ['D'], ['A', 'B'], ['A', 'C'], ['A', 'D'], ['B', 'C'], ['B', 'D'], ['C', 'D'], ['A', 'B', 'C'], ['A', 'B', 'D'], ['A', 'C', 'D'], ['B', 'C', 'D'], ['A', 'B', 'C', 'D']]
When I bump the number of items to 10, 15, 2010 1023 15 32767 20 1048575 30 1073741823The number of combinations = 2**num_items - 1.
The time for computing the combinations of 20 items is about 2 seconds on my laptop. If the item count is 30, the number of combinations is 1024 times greater, and I would expect it to take about 2048 seconds to compute.