Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 函数中索引的参数_Python - Fatal编程技术网

Python 函数中索引的参数

Python 函数中索引的参数,python,Python,我在做一个函数,我想要它,这样你就可以输入一个列表的索引作为参数,我怎么做呢 Map = {'room11' : [[1,1,1,2,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,2],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]], 'room21' : [[1,1,1,2,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[2,0,0,0,0,

我在做一个函数,我想要它,这样你就可以输入一个列表的索引作为参数,我怎么做呢

Map = {'room11' : [[1,1,1,2,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,2],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]],
       'room21' : [[1,1,1,2,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[2,0,0,0,0,0,2],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]],
       'room31' : [[1,1,1,2,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[2,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]],
       'room12' : [[1,1,1,2,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,2],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,2,1,1,1]],
       'room22' : [[1,1,1,2,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[2,0,0,0,0,0,2],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,2,1,1,1]],
       'room32' : [[1,1,1,2,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[2,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,2,1,1,1]],
       'room13' : [[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,2],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,2,1,1,1]],
       'room23' : [[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[2,0,0,0,0,0,2],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,2,1,1,1]],
       'room33' : [[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[2,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,2,1,1,1]]
       }
我想要这样的东西(这显然不起作用):

它将返回以下内容:

Map['room11'][2][1]

只需按如下方式传递地图和坐标:

def move_up(Map, coord):
    x, y = coord
    return Map['room<num>'][x+1][y])

# call like this:
move_up(Map, (1, 1) )

做得好,张贴代码“显然不起作用”。很多新程序员没有勇气采取这一步,但这正是这类代码的正确论坛。你确实帮了我很多,现在我的代码是:def move_up(room,coord):List,Index=coord#我认为List和Index是更精确的变量返回Map[room][List+1][Index]move_up(Map('room11'),(1,1))我收到一个类型错误,因为字典不能调用。编辑:没有注意到代码会很难阅读哦,我不知道为什么我会这样评论,这个错误是不言自明的,我只需要在没有使用dict的情况下调用它,谢谢!
Map['room11'][2][1]
def move_up(Map, coord):
    x, y = coord
    return Map['room<num>'][x+1][y])

# call like this:
move_up(Map, (1, 1) )