接受列表列表并返回包含这些列表内容的单个列表的函数是否有一个通用名称?
编辑:我的问题最初是“是否有一个标准名称可以扁平化列表列表,但只有一层深?”,但查克的答案的措辞更接近我真正想问的内容,所以我重命名了它。不过,这三个答案对我都很有用。谢谢。
对于一个函数来说,“flatten”似乎是一个广为接受的名称,该函数采用一棵树并构建一个原子列表,无论它们嵌套的深度如何,但是如果一个函数在一层后就停止呢?所以 ((1 2) ((3 4) (5 6)) (7 8)) “东西”到 (1 2 (3 4) (5 6) 7 8)。 “某物”在多种语言/库中是否有通用名称?
这个问题的答案:
Flattening a Shoulder List in Python
表明“链” ’可能是一个不错的猜测,但它是否足够普遍以成为“标准”?
EDIT: My question was originally "Is there a standard name for a function that flattens a list of lists, but only one level deep?", but Chuck's answer is phrased much closer to what I actually wanted to ask, so I renamed it. All three answers were useful to me, though. Thanks.
'flatten' seems to be a well-accepted name for a function that takes a tree and builds a list of atoms however deep they are nested, but what about a function that stops after just one level? So ((1 2) ((3 4) (5 6)) (7 8)) "somethings" to (1 2 (3 4) (5 6) 7 8). Does "something" have a common name across multiple languages/libraries?
The answers to this question:
Flattening a shallow list in Python
suggest that 'chain' might be a good guess, but is it common enough to be "standard"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于删除列表列表的一组内部括号,
concat
非常流行。一个更通用的函数,用于将M
中的M
展平为一个 monadM
,通常称为join
。在抽象代数中,该函数标准称为μ
。For removing an inner set of brackets of a list of lists,
concat
is very popular. A more general function, for flattening anM
ofM
s for a monadM
, is often calledjoin
. In abstract algebra, this function is standardly calledµ
.接受列表列表并返回包含这些列表内容的单个列表的函数在许多函数语言(例如 OCaml、F#、Haskell、Clojure)中称为“concat”。
The function that takes a list of lists and returns a single list containing the contents of those lists is called "concat" in many functional languages (e.g. OCaml, F#, Haskell, Clojure).
我不确定是否有一个标准名称。我可以用 3 个不同的名称来命名 3 个不同的实现
I'm not sure there is a standard name for this. I can name 3 different implementations with 3 different names
在 Common Lisp 中,您可以使用正确的类型参数应用 APPEND 或 CONCATENATE。 APPEND 的结果与参数列表共享子结构; CONCATENATE 总是复制,也可以应用于非列表序列。
In Common Lisp, you can apply APPEND, or CONCATENATE with the right type parameter. The result of APPEND shares substructure with the argument lists; CONCATENATE always copies, and can also be applied to non-list sequences.