接受列表列表并返回包含这些列表内容的单个列表的函数是否有一个通用名称?

发布于 2024-08-14 05:09:15 字数 460 浏览 5 评论 0原文

编辑:我的问题最初是“是否有一个标准名称可以扁平化列表列表,但只有一层深?”,但查克的答案的措辞更接近我真正想问的内容,所以我重命名了它。不过,这三个答案对我都很有用。谢谢。

对于一个函数来说,“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

溺孤伤于心 2024-08-21 05:09:15

对于删除列表列表的一组内部括号concat非常流行。一个更通用的函数,用于将 M 中的 M 展平为一个 monad M,通常称为 join。在抽象代数中,该函数标准称为μ

For removing an inner set of brackets of a list of lists, concat is very popular. A more general function, for flattening an M of Ms for a monad M, is often called join. In abstract algebra, this function is standardly called µ.

默嘫て 2024-08-21 05:09:15

接受列表列表并返回包含这些列表内容的单个列表的函数在许多函数语言(例如 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).

苄①跕圉湢 2024-08-21 05:09:15

我不确定是否有一个标准名称。我可以用 3 个不同的名称来命名 3 个不同的实现

  • Python: chain
  • F#: concat
  • LINQ: SelectMany

I'm not sure there is a standard name for this. I can name 3 different implementations with 3 different names

  • Python: chain
  • F#: concat
  • LINQ: SelectMany
酒与心事 2024-08-21 05:09:15

在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文