python all possible pairs of 2 list elements, and getting the index of that pair

前端 未结 1 1774
后悔当初
后悔当初 2021-02-12 07:20

let\'s say I have two lists:

a = list(1,2,3)
b = list(4,5,6)

So I can have 9 pairs of these list members:

(1,4)
(1,5)
(1,6)

(2         


        
相关标签:
1条回答
  • 2021-02-12 08:03

    And to complete the answer and stay in the example:

    import itertools  
    
    a = [1, 2, 3]
    b = [4, 5, 6]
    c = list(itertools.product(a, b))
    
    idx = c.index((1,4))
    

    But this will be the zero-based list index, so 0 instead of 1.

    0 讨论(0)
提交回复
热议问题