It's been over a year since I've used Mathematica, and I'm having a total brain fart on a home project. I'd like to take an existing list of lists, say,
x = {{1, 2}, {3, 4}, {5, 6}}
and append 9 and 10 onto the end of each sublist of x to get a list y, where
y = {{1, 2, 9}, {1 ,2, 10}, {3, 4, 9}, {3, 4, 10}, {5, 6, 9}, {5, 6, 10}}
I'm sure there's a built-in function to do this, but cannot recall it for the life of me.
Answer
x = {{1, 2}, {3, 4}, {5, 6}};
y = {9, 10};
Flatten /@ Tuples[{x, y}]
(*
{{1, 2, 9}, {1, 2, 10}, {3, 4, 9}, {3, 4, 10}, {5, 6, 9}, {5, 6, 10}}
*)
Comments
Post a Comment