我们如何获取特定索引列表的元素?

How can we fetch the elements of the list of specific index?

我有一个 python 列表说

a= ['Sample Date', '4/21/2015', '10/14/2014', '9/16/2014', '7/10/2014', '8/11/2014', '8/3/2014', '7/20/2014', '7/6/2014', '8/11/2014', '8/11/2014', '8/11/2014'] 

我有一个索引列表属于列表一个说

b=[5, 9, 10, 11].

获得以下输出的代码应该是什么

c= ['7/20/2014', '7/6/2014','7/20/2014', '7/6/2014']

使用简单的列表理解

>>> a= ['Sample Date', '4/21/2015', '10/14/2014', '9/16/2014', '7/10/2014', '8/11/2014', '8/3/2014', '7/20/2014', '7/6/2014', '8/11/2014', '8/11/2014', '8/11/2014'] 
>>> b=[5, 9, 10, 11]
>>> [a[i-1] for i in b]
['7/10/2014', '7/6/2014', '8/11/2014', '8/11/2014']

或者

>>> [a[i] for i in b]
['8/11/2014', '8/11/2014', '8/11/2014', '8/11/2014']

如果基于第0个索引

operator.itemgetter 正是这样做的

>>> from operator import itemgetter
>>> a = ['Sample Date', '4/21/2015', '10/14/2014', '9/16/2014', '7/10/2014', '8/11/2014', '8/3/2014', '7/20/2014', '7/6/2014', '8/11/2014', '8/11/2014', '8/11/2014'] 
>>> getitems = itemgetter(5, 9, 10, 11)
>>> getitems(a)
('8/11/2014', '8/11/2014', '8/11/2014', '8/11/2014')