【发布时间】:2014-05-25 07:28:02
【问题描述】:
使用 Python 的切片运算符,例如可以实现:
a = [0, 10, 20, 30, 40, 50]
>>> a[0:5:2]
[0, 20, 40]
如果我想以任意顺序访问列表的元素,我该怎么办?我想做的是这样的:
>>> a([1,0,3,5]) #MATLAB notation!
[10, 0, 30, 50]
(I know how to do this with numpy,但如果可能的话,我宁愿不导入任何包)。
【问题讨论】:
标签: python list indexing tuples iterable