Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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_Arrays - Fatal编程技术网

Python 如何搜索二维数组并返回元素

Python 如何搜索二维数组并返回元素,python,arrays,Python,Arrays,在我的程序中,我希望用户输入一个数字和要搜索的数字,并从2D数组返回元素 例如,如果输入=1,则数组[1][1,2,3,4,5,6]并分别数组[1][7,8] player = [[2, 17, 19, 19, 21, 29, 8, 17],[9, 5, 17, 18, 23, 28, 2, 2],[5, 8, 18, 18, 29, 30, 25, 26],[5, 6, 15, 13, 23, 24, 12, 12]] playerID = int(input("Please ent

在我的程序中,我希望用户输入一个数字和要搜索的数字,并从2D数组返回元素

例如,如果输入=1,则数组[1][1,2,3,4,5,6]并分别数组[1][7,8]

player = [[2, 17, 19, 19, 21, 29, 8, 17],[9, 5, 17, 18, 23, 28, 2, 2],[5, 8, 18, 18, 29, 30, 25, 26],[5, 6, 15, 13, 23, 24, 12, 12]]
playerID = int(input("Please enter player ID "))
print(playerID)
for i in array(playerID):
   for j in array(6):
       print(array[i][j])
else:
   print("not found")
player=[[2,17,19,19,21,29,8,17],[9,5,17,18,23,28,2,2],[5,8,18,18,29,30,25,26],[5,6,15,13,23,24,12,12]]
playerID=int(输入(“请输入玩家ID”))
对于播放器中的p:
如果p[:6]中的playerID:
打印([playerID],p[:6])
打印([playerID],p[6:])
输出

请输入玩家ID 5
[5] [9, 5, 17, 18, 23, 28]
[5] [2, 2]
[5] [5, 8, 18, 18, 29, 30]
[5] [25, 26]
[5] [5, 6, 15, 13, 23, 24]
[5] [12, 12]
player=[[2,17,19,19,21,29,8,17],[9,5,17,18,23,28,2,2],[5,8,18,18,29,30,25,26],[5,6,15,13,23,24,12]]
playerID=int(输入(“请输入玩家ID”))
对于播放器中的p:
如果p[:6]中的playerID:
打印([playerID],p[:6])
打印([playerID],p[6:])
输出

请输入玩家ID 5
[5] [9, 5, 17, 18, 23, 28]
[5] [2, 2]
[5] [5, 8, 18, 18, 29, 30]
[5] [25, 26]
[5] [5, 6, 15, 13, 23, 24]
[5] [12, 12]

它是numpy数组还是列表?它不是numpy数组,它是2D列表?它是numpy数组还是列表?它不是numpy数组,它是2D列表这会打印所有具有数字5的元素列表。例如,我试图实现的是
如果输入=1,那么数组**[1][1,2,3,4,5,6]**
它应该只返回该列表的元素。如果输入=5,您可以在
播放器上提供预期结果
数据
?这将打印所有具有数字5的元素列表。例如,我试图实现的是
如果输入=1,那么数组**[1][1,2,3,4,5,6]**
它应该只返回该列表的元素。如果输入=5
,您能提供
播放器的预期结果吗?
pseudocode

get playerID 
print playerID
search for playerID in player
    access the elements upto 6 
        print player[playerID] [player's Elements] 
else
    print not found