Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [[0, 1, 0, 1, 0, 1, 0, 1],
- [1, 0, 1, 0, 1, 0, 1, 0],
- [0, 1, 0, 1, 0, 1, 0, 1],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [-1, 0, -1, 0, -1, 0, -1, 0],
- [0, -1, 0, -1, 0, -1, 0, -1],
- [-1, 0, -1, 0, -1, 0, -1, 0]]
- import random
- random.choice([(i, j) for i, row in enumerate(x) for j, val in enumerate(row) if val == 1])
- indices = []
- for row_idx in range(len(a)):
- for col_idx in range(len(a[row_idx])):
- num = a[row_idx][col_idx]
- if num == 1:
- indices.append((row_idx, col_idx))
- import random
- rand_idx = random.randrange(0, len(indices))
- print indices[rand_idx]
Add Comment
Please, Sign In to add comment