-2

I'd like to know what is the pythonic way to generate all tuples (x, y) where x and y are integers in a certain range. I need it to generate n points and I don't want to take the same point two or more times.

canaio
  • 3
  • 4
  • 2
    Do you currently have a non-pythonic way what works? – OneCricketeer Feb 11 '16 at 22:03
  • 1
    Could you give us an example of what you're looking for? – zondo Feb 11 '16 at 22:04
  • 2
    Possible duplicate: http://stackoverflow.com/q/533905/190597 – unutbu Feb 11 '16 at 22:05
  • Your question is not very clear. Are you looking for the product, or combinations, or permutations maybe? Best show us an example. Anyway, for all of those the "pythonic" way probably is just to use one of the many functions of [`itertools`](https://docs.python.org/3/library/itertools.html) – tobias_k Feb 11 '16 at 22:08
  • Possible duplicate (if looking for combinations): http://stackoverflow.com/q/464864/190597 – unutbu Feb 11 '16 at 22:11

1 Answers1

3

The most Pythonic way is to use the standard library:

>>> import itertools
>>> itertools.product(range(3), range(4))
<itertools.product object at 0x7f2b5c8bc510>
>>> list(_)
[(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1),
 (1, 2), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3)]
orlp
  • 112,504
  • 36
  • 218
  • 315