• <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“列表索引必须是整数,而不是元组"错误

        Python #39;list indices must be integers, not tuplequot; error(Python“列表索引必须是整数,而不是元组错误)
      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“列表索引必须是整数,而不是元组"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)

                  <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>
                            <tbody id='zJEUX'></tbody>
                            <bdo id='zJEUX'></bdo><ul id='zJEUX'></ul>