-1

I have two lists;

top_value=[466, 482, 508, 523, 543, 564, 583]
left_value= [103, 129, 206, 470, 536, 567, 669, 766]

result;

[[103,466],[103,482],[103,508],[103,523],[103,543],[103,583]],[[129,466],[129,482]...],[[206,466],[.....]],[[,,,]] ....

I tried the itertools permutation and combination methods and got results that are repeated or unordered. I want to get result. overall there should be 56 binary elements. Is there any other method?

thank you

ysmnrn.dll
  • 45
  • 5
  • 1
    This is a task, not a question. What have you tried, why did it fail? – Mr. T Jan 18 '22 at 09:02
  • 1
    Does this answer your question? [Get the cartesian product of a series of lists?](https://stackoverflow.com/questions/533905/get-the-cartesian-product-of-a-series-of-lists) – Bharel Jan 18 '22 at 09:05
  • typing quickly caused me to make mistakes. I am very sorry – ysmnrn.dll Jan 18 '22 at 09:48

1 Answers1

1

You're looking for itertools.product, which creates the Cartesian product of the passed iterables.

from itertools import product
out = list(product(left_value, top_value))

Output:

[(103, 466), (103, 482), (103, 508), (103, 523), (103, 543), (103, 564), (103, 583), (129, 466), (129, 482), (129, 508), (129, 523), (129, 543), (129, 564), (129, 583), (206, 466), (206, 482), (206, 508), (206, 523), (206, 543), (206, 564), (206, 583), (470, 466), (470, 482), (470, 508), (470, 523), (470, 543), (470, 564), (470, 583), (536, 466), (536, 482), (536, 508), (536, 523), (536, 543), (536, 564), (536, 583), (567, 466), (567, 482), (567, 508), (567, 523), (567, 543), (567, 564), (567, 583), (669, 466), (669, 482), (669, 508), (669, 523), (669, 543), (669, 564), (669, 583), (766, 466), (766, 482), (766, 508), (766, 523), (766, 543), (766, 564), (766, 583)]