Clojure:半展平嵌套序列 [英] Clojure: Semi-Flattening a nested Sequence
本文介绍了Clojure:半展平嵌套序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个嵌入向量列表的列表,它看起来像:
I have a list with embedded lists of vectors, which looks like:
(([1 2]) ([3 4] [5 6]) ([7 8]))
我知道与之合作并不理想.我想将其展平为 ([1 2] [3 4] [5 6] [7 8])
.
Which I know is not ideal to work with. I'd like to flatten this to ([1 2] [3 4] [5 6] [7 8])
.
flatten 不起作用:它给了我 (1 2 3 4 5 6 7 8)
.
flatten doesn't work: it gives me (1 2 3 4 5 6 7 8)
.
我该怎么做?我想我需要根据每个列表项的 contents 创建一个新列表,而不是项目,这是我无法从文档中找到如何做的部分.
How do I do this? I figure I need to create a new list based on the contents of each list item, not the items, and it's this part I can't find out how to do from the docs.
推荐答案
如果你只想把它扁平化一级,你可以使用 concat
If you only want to flatten it one level you can use concat
(apply concat '(([1 2]) ([3 4] [5 6]) ([7 8])))
=> ([1 2] [3 4] [5 6] [7 8])
这篇关于Clojure:半展平嵌套序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文