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,
Try to use list generator to create the nested lists:
>>> [[[x,y] for x in list1] for y in list2] [[[1, 3], [2, 3]], [[1, 4], [2, 4]]] >>>
Or, if you want one-line list, just delete brackets:
>>> [[x,y] for x in list1 for y in list2] [[1, 3], [1, 4], [2, 3], [2, 4]]