||
I. access multi elements of a list knowing their indices
You can use operator.itemgetter:
>>>from operator import itemgetter
>>> a =[-2,1,5,3,8,5,6]
>>> b =[1,2,5]
>>>print itemgetter(*b)(a)(1,5,5)
Or you can use numpy:
>>>import numpy as np
>>> a = np.array([-2,1,5,3,8,5,6])
>>> b =[1,2,5]>>>print list(a[b])[1,5,5]
Or you can
>>>a =[-2,1,5,3,8,5,6]
>>>b =[1,2,5]
>>>c =[ a[i]for i in b]
II.Get the difference set of two lists
>>>list(set(temp1)- set(temp2))
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-7-27 04:24
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社