Python: filtering lists by indices

后端 未结 7 1086
情深已故
情深已故 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']
    
    0 讨论(0)
提交回复
热议问题