• <legend id='TLeGC'><style id='TLeGC'><dir id='TLeGC'><q id='TLeGC'></q></dir></style></legend>
  • <i id='TLeGC'><tr id='TLeGC'><dt id='TLeGC'><q id='TLeGC'><span id='TLeGC'><b id='TLeGC'><form id='TLeGC'><ins id='TLeGC'></ins><ul id='TLeGC'></ul><sub id='TLeGC'></sub></form><legend id='TLeGC'></legend><bdo id='TLeGC'><pre id='TLeGC'><center id='TLeGC'></center></pre></bdo></b><th id='TLeGC'></th></span></q></dt></tr></i><div id='TLeGC'><tfoot id='TLeGC'></tfoot><dl id='TLeGC'><fieldset id='TLeGC'></fieldset></dl></div>
    • <bdo id='TLeGC'></bdo><ul id='TLeGC'></ul>

    <tfoot id='TLeGC'></tfoot>

    <small id='TLeGC'></small><noframes id='TLeGC'>

      1. Python“列表索引必须是整数,而不是元组"错误

        时间:2023-07-23
      2. <i id='fCXvm'><tr id='fCXvm'><dt id='fCXvm'><q id='fCXvm'><span id='fCXvm'><b id='fCXvm'><form id='fCXvm'><ins id='fCXvm'></ins><ul id='fCXvm'></ul><sub id='fCXvm'></sub></form><legend id='fCXvm'></legend><bdo id='fCXvm'><pre id='fCXvm'><center id='fCXvm'></center></pre></bdo></b><th id='fCXvm'></th></span></q></dt></tr></i><div id='fCXvm'><tfoot id='fCXvm'></tfoot><dl id='fCXvm'><fieldset id='fCXvm'></fieldset></dl></div>

      3. <tfoot id='fCXvm'></tfoot>
        • <bdo id='fCXvm'></bdo><ul id='fCXvm'></ul>
            <tbody id='fCXvm'></tbody>

            • <legend id='fCXvm'><style id='fCXvm'><dir id='fCXvm'><q id='fCXvm'></q></dir></style></legend>

                <small id='fCXvm'></small><noframes id='fCXvm'>

                  本文介绍了Python“列表索引必须是整数,而不是元组"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I'm working on moving a robot around a 2d grid room of 8 x 8, and one part is initialising the sensors which consist of the closest 5 tiles around the robot.

                  self.sensors = [0 for x in xrange(5)]
                  

                  here I'm creating an empty of array of 5 elements.

                  but when I attempt to set the value of sensors like this:

                      if self.heading == 'East':
                          self.sensors[0] = self.room[self.x, self.y-1]
                          self.sensors[1] = self.room[self.x+1, self.y-1]
                          self.sensors[2] = self.room[self.x+1, self.y]
                          self.sensors[3] = self.room[self.x+1, self.y+1]
                          self.sensors[4] = self.room[self.x, self.y+1]
                  

                  I get the error of 'list indices must be integers, not tuples'.

                  解决方案

                  You say self.room is a "2d grid" -- I assume it is a list of lists. In this case, you should access its elements as

                  self.room[self.x][self.y-1]
                  

                  instead of indexing the outer list with the pair self.x, self.y-1.

                  这篇关于Python“列表索引必须是整数,而不是元组"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:框架内的网格? 下一篇:如何用 3 个数组做彩色 2D 网格

                  相关文章

                  <small id='zJEUX'></small><noframes id='zJEUX'>

                    <tfoot id='zJEUX'></tfoot><legend id='zJEUX'><style id='zJEUX'><dir id='zJEUX'><q id='zJEUX'></q></dir></style></legend>

                    1. <i id='zJEUX'><tr id='zJEUX'><dt id='zJEUX'><q id='zJEUX'><span id='zJEUX'><b id='zJEUX'><form id='zJEUX'><ins id='zJEUX'></ins><ul id='zJEUX'></ul><sub id='zJEUX'></sub></form><legend id='zJEUX'></legend><bdo id='zJEUX'><pre id='zJEUX'><center id='zJEUX'></center></pre></bdo></b><th id='zJEUX'></th></span></q></dt></tr></i><div id='zJEUX'><tfoot id='zJEUX'></tfoot><dl id='zJEUX'><fieldset id='zJEUX'></fieldset></dl></div>
                        <bdo id='zJEUX'></bdo><ul id='zJEUX'></ul>