Guest User

Untitled

a guest
Jan 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. [[0, 1, 0, 1, 0, 1, 0, 1],
  2. [1, 0, 1, 0, 1, 0, 1, 0],
  3. [0, 1, 0, 1, 0, 1, 0, 1],
  4. [0, 0, 0, 0, 0, 0, 0, 0],
  5. [0, 0, 0, 0, 0, 0, 0, 0],
  6. [-1, 0, -1, 0, -1, 0, -1, 0],
  7. [0, -1, 0, -1, 0, -1, 0, -1],
  8. [-1, 0, -1, 0, -1, 0, -1, 0]]
  9.  
  10. import random
  11. random.choice([(i, j) for i, row in enumerate(x) for j, val in enumerate(row) if val == 1])
  12.  
  13. indices = []
  14. for row_idx in range(len(a)):
  15. for col_idx in range(len(a[row_idx])):
  16. num = a[row_idx][col_idx]
  17. if num == 1:
  18. indices.append((row_idx, col_idx))
  19.  
  20. import random
  21. rand_idx = random.randrange(0, len(indices))
  22. print indices[rand_idx]
Add Comment
Please, Sign In to add comment