0

I understand that the codes below generate a random position from (0,1) to (48,48). I would like to understand the technique used. Is it a tuple comprehension? Great appreciate all your explanations.

import random
BOARD_SIZE=(48,48)

position = tuple(random.randrange(BOARD_SIZE[i]) for i in (0,1))
print(position)
Uncle Bob
  • 1
  • 1

1 Answers1

0

Indeed, the technique used here is a tuple comprehension.

The code is pretty straightforward, first you define BOARD_SIZE, the first value is the upper bound of the first value in the position, same applies for the second one.

The output will be (x, y) where x and y are random values in range(48).

Hamza Hathoute
  • 438
  • 3
  • 12
  • Is it defined as tuple comprehension or generator expression with the following format. genexpr = (expression for item in collection) – Uncle Bob Jul 01 '20 at 04:50