你如何找到列表的所有子序列? [英] How do you find all of the subsequences of a list?

查看:259
本文介绍了你如何找到列表的所有子序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图学习如何列出理解,并试图找出一种方法来查找列表的所有子序列,但我不太确定如何去解决这个问题。任何人都可以帮助我吗?

I'm trying to learn how to list comprehension and I'm trying to figure out a way to find all the subsequences of a list but i'm not quite sure how one would go about that. Could anyone help me?

推荐答案

另一个有趣的解决方案是:

Just another interesting solution:

filterM (const [True,False]) [1,2,3]

我读取如下:返回包含或不包含列表元素的可能组合。这个解释可能不会使用正确的术语,但是我直观地理解它。对于每个元素, const 的计算结果为 [True,False] ,因此每个元素都包含在或不包含在结果中。使用 filterM ,这里的谓词位于monad列表中,所以我们得到了可能结果的列表。

I read this as follows: Return the possible combinations of including or not including an element of the list. This explanation might not be using the correct terminology, but it's how I intuitively understand it. const evaluates to [True,False] for every element, so every element is included or not included in the result. Using filterM, the predicate here is in the list monad, so we get a list of the possible results.

这篇关于你如何找到列表的所有子序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆