I have two lists shaped like the following:
listA
[[778, 606],
[2115, 2049],
[3361, 3183],
[4512, 4179]]
listB
[[-128, -4],
[-38, 38],
[-15, 110],
[-105, 185]]
I want to take the first element from listA and listB, to create a list that will go into another list.
So I want an output like the following:
new_list
[[[778, 606],[-128, -4]],
[[2115, 2049],[-38, 38]],
[[3361, 3183],[-15, 110]],
[[4512, 4179],[-105, 185]]]
Thoughts on how to properly structure the list comprehension or maybe theres a better out of the box method?
I think I'm struggling with the logic of how to append lists.
I've tried the following:
x = []
for i,j in [(i,j) for i in listA for j in listB]:
x.append(i)
x.append(j)
which resulted in:
[[778, 606],
[-128, -4],
[778, 606],
[-38, 38],
[778, 606],
[-15, 110],
[778, 606],
[-105, 185]]
Which isn't what I wanted. So I also tried:
y = [(i,j) for i in listA for j in listB]
which resulted in:
[([778, 606], [-128, -4]),
([778, 606], [-38, 38]),
([778, 606], [-15, 110]),
([778, 606], [-105, 185]),
([2115, 2049], [-128, -4]),
([2115, 2049], [-38, 38]),
([2115, 2049], [-15, 110]),
([2115, 2049], [-105, 185]),
([3361, 3183], [-128, -4]),
([3361, 3183], [-38, 38]),
([3361, 3183], [-15, 110]),
([3361, 3183], [-105, 185]),
([4512, 4179], [-128, -4]),
([4512, 4179], [-38, 38]),
([4512, 4179], [-15, 110]),
([4512, 4179], [-105, 185])]