Answer the question
In order to leave comments, you need to log in
How to generate the following list of lists from numbers?
In general, this is the situation.
There is a list of numbers, for example: five_group = [3, 5, 13, 18, 20]
You need to generate a list of all combinations of 5 numbers out of 25, each of which contains at least one of the numbers with five_group.
The end result should be a list like this:
LIST =
COMBINATIONS = [list(i) for i in itertools.combinations(range(1, 26), 5)]
Answer the question
In order to leave comments, you need to log in
each of which contains at least one of the numbers with five_group.
five_group = set([3, 5, 13, 18, 20])
COMBINATIONS = [list(i) for i in itertools.combinations(
range(1, 26), 5) if five_group.intersection(i)]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question