-1

So I would have 2 lists, with a random amount of values. for example:

listx = [15513, 813, 984949, 5000], listj = [76815, 75, 8484, 9419419, 418841814, 84848, 84848]

How would I generate every possible combination of these lists? Like:

combination = [15513, 75, 9419419]

it can take as much values as it wants from both list to use in the combination, I want to check every single combination, like it can take 2 values from the first one and 5 from the other, or all from the first one and 3 from the other.

Gumball
  • 19
  • 6
  • 1
    Seems like you forgot to include your attempt? – Jab Jun 03 '21 at 17:35
  • Look into the itertools (combination, permutation, product, etc.) – Jan Jun 03 '21 at 17:36
  • You look up how to do combinations in Python and write your code. See [How much research?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). If you have trouble with that code, *then* you might have a Stack Overflow question. – Prune Jun 03 '21 at 17:40
  • I didn't have an attempt since I didn't know where to start – Gumball Jun 03 '21 at 17:41

1 Answers1

1

TRY:

from itertools import combinations, chain

listx = [15513, 813, 984949, 5000]
listj = [76815, 75, 8484, 9419419, 418841814, 84848, 84848]

for i in range(2, len(listx) + len(listj)):
    print(list(combinations(chain(*[listx,listj]), i)))
Nk03
  • 14,699
  • 2
  • 8
  • 22