title: Move element in 2d array in Python
body: <p>I have this function, which sometimes works, sometimes doesn't:</p>
  <pre><code>def movecell(x1,y1,x2,y2):
      global PG
      global SIZEX
      global SIZEY
      print(f&quot;{x1}:{y1}-&gt;{x2}:{y2}&quot;)
      print()
      if x2 &gt;= 0 and x2 &lt; SIZEX:
          print(&quot;x good&quot;)
          if y2 &gt;= 0 and y2 &lt; SIZEY:
              print(&quot;y good&quot;)
              if PG[x2][y2] == emparr:
                  print(&quot;all good&quot;)
                  print()
                  print(PG[x1][y1])
                  PG[x2][y2] = PG[x1][y1]
                  print(PG[x2][y2])
                  PG[x1][y1] = emparr
                  print(PG[x1][y1])
  </code></pre>
  <p>this function gives the instrutions to the one above:</p>
  <pre><code>def act(id):
      cx = 0
      cy = 0
      for i in PG:
          for j in i:
              if j[0] == id:
                  #print(id)
                  cx=PG[PG.index(i)].index(j)
                  cy=PG.index(i)
      dx = math.floor(random.randrange(-1,2))
      dy = math.floor(random.randrange(-1,2))
      print(f&quot;{cx}:{cy}-&gt;{cx+dx}:{cy+dy}&quot;)
      movecell(cx,cy,cx+dx,cy+dy
  </code></pre>
  <p>PG is a 3D array, SIZEX is it's &quot;width&quot; and SIZEY is it's &quot;height&quot;.
  Each &quot;cell&quot; contains a list of 5 integers
  Emparr is an array of empty values, to make it easier</p>
  <pre><code>SIZEX = 6
  SIZEY = 6
  PG = [[[None for i in range(5)] for j in range(SIZEY)]for k in range(SIZEX)]
  emparr = [None for i in range(5)]
  </code></pre>
  <p>If you set a value of PG[n][k][0] to something, and try to move it, it'll look like</p>
  <pre><code>PG[2][2][0] = 2
  act(2) 
  </code></pre>
  <p>Of course you have to import random and math</p>
  <pre><code>import math
  import random
  </code></pre>
  <p>I've tried filling it up with some random numbers on random places, and move some of them, and it works, except for when it doesn't.</p>