Python Fastest way to find Indexes of item in list

前端 未结 6 1903
半阙折子戏
半阙折子戏 2020-12-19 06:50

If one was to attempt to find the indexes of an item in a list you could do it a couple different ways here is what I know to be the fastest

aList = [123, \'         


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-19 07:14

    Simply create a dictionary of item->index from the list of items using zip like so:

    items_as_dict = dict(zip(list_of_items,range(0,len(list_of_items))))
    index = items_as_dict(item)
    

提交回复
热议问题