I recently came across this notation
a = [1,2,3,4]
b = [2,4,6]
c = [(x,y,z) for x in a for y in b for z in a]
First I don't know how to search for the notation in creating c
, is there a name for this type of structure?
Also, I'm confident that c
can be updated to not allow x
to equal z
. Please can you help me with this?
I've tried various things on the lines of
c = [(x,y,z) for x in a for y in b for z in a for x != z]
but so far I can't find anything that works, or is even valid syntax.
What I'm trying to accomplish is to find every combination of (a,b,a)
where a
can only be used once in each line so the result would be
[(1, 2, 2),
(1, 2, 3),
(1, 2, 4),
(1, 4, 2),
(1, 4, 3),
(1, 4, 4),
(1, 6, 2),
(1, 6, 3),
(1, 6, 4),
(2, 2, 1),
(2, 2, 3),
(2, 2, 4),
(2, 4, 1),
(2, 4, 3),
(2, 4, 4),
(2, 6, 1),
(2, 6, 3),
(2, 6, 4),
(3, 2, 1),
(3, 2, 2),
(3, 2, 4),
(3, 4, 1),
(3, 4, 2),
(3, 4, 4),
(3, 6, 1),
(3, 6, 2),
(3, 6, 4),
(4, 2, 1),
(4, 2, 2),
(4, 2, 3),
(4, 4, 1),
(4, 4, 2),
(4, 4, 3),
(4, 6, 1),
(4, 6, 2),
(4, 6, 3)]
Thanks
See Question&Answers more detail:os