1

Suppose I have 4 lists.

group = [1]
question_number = [1,2,20,22,34,36]
response = range(1,6)
score = range(100,-1,-25)

I'd like to get all tuples of selecting one element from each list.

(1,1,1,100)
(1,1,1,75)
...
(1,36,5,0)

I could do this with loop, but I am wondering if itertools has something easier? I know itertools.combinations can get all combos of length n. Is there a similar function for multiple lists?

Demetri Pananos
  • 6,770
  • 9
  • 42
  • 73

1 Answers1

1

I forgot this was called the Cartesian product. I used itertools.product to get what I wanted.

Demetri Pananos
  • 6,770
  • 9
  • 42
  • 73