using index() on multidimensional lists

前端 未结 8 2102
北恋
北恋 2020-12-10 03:00

For a one dimensional list, the index of an item is found as follows:

 a_list = [\'a\', \'b\', \'new\', \'mpilgrim\', \'new\']
 a_list.index(\'mpilgrim\')
         


        
8条回答
  •  余生分开走
    2020-12-10 03:55

    A multidimensional list is simply a list with more lists inside of it. So its indices would be lists themselves.

    a = [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
    print a.index([2, 3, 4])
    # prints 1
    

提交回复
热议问题