2024-05-13 09:47:29 发布
网友
我有一个阵列
a=[0, 10, 20, 30, 40, 50, 60]
我选择了第二和第三个元素
获取
array([10, 20])
如何选择a的其他元素,除了我已经选择的元素?在
a
也就是说,我想获得:
array([0, 30, 40, 50, 60])
逻辑上应该是
a[![1,2]]
像这样:
a=[0, 10, 20, 30, 40, 50, 60] b = a[1:3] c =[x for x in a if x not in b] print(a) print(b) print(c)
输出:
如果顺序无关紧要,可以将列表填充到集合中并使用these set operations: yourSet.union(otherSet),yourSet.intersect(otherSet)`你的。区别(其他设置)等
yourSet.union(otherSet)
yourSet.intersect(otherSet)
对于python 2.7,最简单的解决方案是:
a=[0, 10, 20, 30, 40, 50, 60] c=[1,2] values = [a[i] for i, x in enumerate(a) if i not in c] print values [0, 30, 40, 50, 60]
像这样:
输出:
^{pr2}$如果顺序无关紧要,可以将列表填充到集合中并使用these set operations:
yourSet.union(otherSet)
,yourSet.intersect(otherSet)
`你的。区别(其他设置)等对于python 2.7,最简单的解决方案是:
相关问题 更多 >
编程相关推荐