Python merging two lists with all possible permutations

后端 未结 7 1729
醉话见心
醉话见心 2020-12-02 15:09

I\'m trying to figure out the best way to merge two lists into all possible combinations. So, if I start with two lists like this:

list1 = [1, 2]
list2 = [3,         


        
相关标签:
7条回答
  • 2020-12-02 15:36

    Edited my code to give you your desired output.

    list1 = [1,2]
    list2 = [3,4]
    combined = []
    
    for a in list1:
        new_list = []
        for b in list2:
            new_list.append([a, b])
        combined.append(new_list)
    
    print combined
    
    0 讨论(0)
提交回复
热议问题