有没有一种方法可以检查球拍的另一个列表中是否包含一个列表的所有元素? [英] Is there a way to check if all elements of a list are contained in another list in racket?
本文介绍了有没有一种方法可以检查球拍的另一个列表中是否包含一个列表的所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个执行以下操作的函数:
>(function '(1 2 3 4) '(1 2 3 4 5))
#t
在这种情况下由于第一个列表的所有元素都包含在第二个列表中而返回#t时.是否有一个功能可以执行而不必担心顺序?
解决方案
据我所知,没有为此内置的函数,并且我认为定义这种函数的最短方法就是这样.
>
(define (list-check l1 l2)
(andmap (λ(x) (not (boolean? (memq x l2)))) l1))
I want a function that does something like this:
>(function '(1 2 3 4) '(1 2 3 4 5))
#t
When in this case is returning #t because all elements of the first list are contained in the second list. Is there a function that does that without having to worry about order?
解决方案
So as far as I know there is no built in function for this, and I believe the shortest way to define such function would be something like this.
(define (list-check l1 l2)
(andmap (λ(x) (not (boolean? (memq x l2)))) l1))
这篇关于有没有一种方法可以检查球拍的另一个列表中是否包含一个列表的所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文