0

Let's say I have a list of lists, like so:

[
  ["A", "B"],
  ["C", "D", "E"]
]

I want to get all possible permutations, which in this case gives me 6 results.

Later, that list gets a new item appended to it:

[
  ["A", "B"],
  ["C", "D", "E"],
  ["F", "G"]
]

I want to use itertools.product to get that set of combos as well, automatically including the new list item.

(This would all be easier if itertools.product took a list of items to combine.)

Is this possible?

XtinaS
  • 194
  • 3
  • 15
  • 2
    "I want to use itertools.product to get that set of combos as well, automatically including the new list item." <- But what's the problem in just doing that? – timgeb Jul 26 '21 at 10:42
  • 2
    e.g. `itertools.product(*your_updated_list_of_lists)`. – timgeb Jul 26 '21 at 10:44
  • 1
    You have a list that contains the arguments that you want to pass separately; that is what the `*` operator is for, as in the linked duplicate. – Karl Knechtel Jul 26 '21 at 10:52
  • 1
    in short, if you have that lists as a variable called `myLists`, you would just call `itertools.product(*myLists)` – Daniel Jul 26 '21 at 10:56
  • Because I never knew what that star operator was even for. Thank y'all! – XtinaS Jul 26 '21 at 11:46

0 Answers0