-1
list1 = [2 3 4]
list2 = [0 1 2 3] 

desired output / or similar

(2,0) (2,1) (2,2) (2,3) (3,0) (3,1) (3,2) (3,3) (4,0)

i.e. for every val in list1, iterate through list2 before moving to next val in list1

I might be here for the next day trying to do it :/ ... tyty

Python learner
  • 1,159
  • 1
  • 8
  • 20
  • 1
    What have you tried so far? The approach you are describing seems to be in the right direction... – Mortz Oct 12 '21 at 10:42
  • 1
    So nested for loop would be a great solution, like mentioned in the comments by Pingu and timgeb already. Did that solve the problem? If not, please spend a little more time improving the original post with your findings. – JustLudo Oct 12 '21 at 10:53
  • https://stackoverflow.com/questions/533905/get-the-cartesian-product-of-a-series-of-lists – wovano Oct 12 '21 at 10:59

2 Answers2

0

You can create an array of tuples which corresponds to each unique link between the values in list1 and list2

linked_values=[]
for i in list1:
    for j in list2:
        linked_values.append((i,j))
Trym Berg
  • 36
  • 5
0

You could use the standard library function itertools.product() for this.

However, for trivial cases, you might as well use this one-liner:

output = [(i, j) for i in list1 for j in list2]
wovano
  • 4,543
  • 5
  • 22
  • 49