python - How to combine two list of lists to a new list -
this question has answer here:
- get cartesian product of series of lists? 10 answers
i have problem this. have 2 lists, , b, a=[[1,2],[3,4],[5,6]]
, b=[["a","b"],["c","d"]]
, got new list these 2
c = [ [[1,2],["a","b"]], [[3,4],["a","b"]], [[1,2],["c","d"]], [[3,4],["c","d"]] ]
i had try following code:
a = [[1,2],[3,4]] b=[["a","b"],["c","d"]] each in a: evey in b: print each.append(evey)
however, output none.
any helpful information appreciated. thank you.
by way, had try replace "append" simple "+". output list elements not list.
this answered here: get cartesian product of series of lists?
try this:
import itertools = [[1,2],[3,4]] b = [["a","b"],["c","d"]] c = [] element in itertools.product(a,b): c.append(list(element)) print c
Comments
Post a Comment