Cartesian product of two or more lists: Difference between revisions

(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 2,259:
NIL</pre>
 
=={{header|Prolog}}==
<lang Prolog>
product([A|_], Bs, [A, B]) :- member(B, Bs).
product([_|As], Bs, X) :- product(As, Bs, X).
</lang>
{{Out}}
<pre>
?- findall(X, product([1,2],[3,4],X), S).
S = [[1, 3], [1, 4], [2, 3], [2, 4]].
 
?- findall(X, product([3,4],[1,2],X), S).
S = [[3, 1], [3, 2], [4, 1], [4, 2]].
 
?- findall(X, product([1,2,3],[],X), S).
S = [].
 
?- findall(X, product([],[1,2,3],X), S).
S = [].
</pre>
=={{header|Python}}==
===Using itertools===
357

edits