返回不在现有列表中的数字范围内的整数值列表:
我有一个值列表:
[0,7,4,5,3,1,4,5,5,1,7,0,7,7,0]
并且想返回不在 [1..8]
范围内的任何值
(即我想返回(从上面的示例)元素 2 、 6 和 8 的形式
[2,6,8]
)
我似乎很难将其组合成一个函数。我知道 notElem
在这里可以很好地工作,但不确定如何将列表 [1..8] 应用于上面显示的值列表以获取当时显示的元素。
I have a list of values:
[0,7,4,5,3,1,4,5,5,1,7,0,7,7,0]
and would like to return any values that are not in the range of [1..8]
(i.e. I would like to return (from the above example) the elements 2, 6 and 8 in the form
[2,6,8]
)
I seem to have trouble putting this together into a function. I know that notElem
would work well here but am not sure on how to apply the list [1..8] to the list of values shown above to get the elements shown just then.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
filter
保留满足条件的元素。或者只是采取 使用
(\\)
运算符补码。Use
filter
to keep elements that satisfies a condition.Or just take the complement using the
(\\)
operator.