Python: filtering lists by indices

后端 未结 7 1090
情深已故
情深已故 2020-12-01 11:56

In Python I have a list of elements aList and a list of indices myIndices. Is there any way I can retrieve all at once those items in aList

7条回答
  •  遥遥无期
    2020-12-01 12:31

    Alternatively, you could go with functional approach using map and a lambda function.

    >>> list(map(lambda i: aList[i], myIndices))
    ['a', 'd', 'e']
    

提交回复
热议问题