【发布时间】:2019-12-17 14:33:38
【问题描述】:
我想创建一个从 1 到 n 的数字数组,没有数字 x,
有没有“更漂亮”的方式来代替[i for i in range(n) if i != x]?
谢谢!
【问题讨论】:
-
为什么
[i for i in range(n) if i != x]不漂亮? -
@AK47 好吧,我正在寻找一种内置的东西,可以让它更短更直接
-
也许是 numpy.where() (docs.scipy.org/doc/numpy/reference/generated/numpy.where.html)
-
@apet,OP 想要内置的东西!
-
我重新打开了这个问题,因为标记的骗子只有纯 python 的解决方案,并且 OP 明确询问了
numpy