Skip to content

Instantly share code, notes, and snippets.

@vanryan
Created July 17, 2016 21:06
Show Gist options
  • Select an option

  • Save vanryan/63506b5645b65d730d55ff2fb8d9910a to your computer and use it in GitHub Desktop.

Select an option

Save vanryan/63506b5645b65d730d55ff2fb8d9910a to your computer and use it in GitHub Desktop.
Computes the cartesian product of input iterables using itertools
from itertools import product
A = map(int,raw_input().split())
B = map(int,raw_input().split())
A.sort()
B.sort()
res = product(A, B)
# you can also get res from
# tmp = [A,B]
# res = list(product(*tmp))
for i in res:
print i,
# you can print faster with:
# print " ".join(map(str, res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment