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.

Revisions

  1. vanryan created this gist Jul 17, 2016.
    18 changes: 18 additions & 0 deletions Cartesian_prod_itertools.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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))