My ultimate goal is a function combining two nested lists, like this:
def tuples_maker(l1, l2):
return sample_data
I know that I can use zip, but I don't know how to utilize "for" loop. I got stuck at first step then I cannot continue....
for example,
l1 = [[1,2,3,4], [10,11,12]]
l2 = [[-1,-2,-3,-4], [-10,-11,-12]]
I want something like this:
[[(1, -1), (2, -2), (3, -3), (4, -4)], [(10, -10), (11, -11), (12, -12)]]
On stack overflow I actually found a solution https://stackoverflow.com/a/13675517/12159353
print(list(zip(a,b) for a,b in zip(l1,l2)))
but it generates a iteration not a list:
[<zip object at 0x000002286F965208>, <zip object at 0x000002286F965AC8>]
so I try not to use list comprehension:
for a,b in zip(l1,l2):
c=list(zip(a,b))
print(c)
it is overlapped:
[(10, -10), (11, -11), (12, -12)]
I know this's not right but I still make a try:
for a,b in zip(l1,l2):
c=list(zip(a,b))
print(c)
Now it seems right, but not a list:
[(1, -1), (2, -2), (3, -3), (4, -4)]
[(10, -10), (11, -11), (12, -12)]
Can anyone help me with this? Thanks in advance!