list - Clojure - 嵌套列表中的对

标签 list dictionary clojure nested

我正在尝试让遍历嵌套列表来收集 Clojure 中的对更加惯用

(def mylist '(
  (2, 4, 6)
  (8, 10, 12)))

(defn pairs [[a b c]]
  (list (list a c)(list b c)))

(mapcat pairs mylist)

;((2 6) (4 6) (8 12) (10 12))

这可以变得更优雅吗?

最佳答案

你的代码很好,但我会使用向量而不是列表

(defn pairs [[x1 x2 y]]
  [[x1 y] [x2 y]])

(mapcat pairs mylist)

关于list - Clojure - 嵌套列表中的对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20610206/

相关文章:

clojure - 捕获序列的头部

python - 将多个基于共同键值的字典合并为一个字典

ruby - 我如何在 Clojure 中编写 Ruby 的 each_cons?

python - 如何使用 Python 将 2 列写入/追加到 .txt 文件中?

java - 使用 Java 写入文件

python - 查找字典中所有键的值中字符串的最大出现次数

python - 从 Python 中的对象列表中删除对象的最快或最惯用的方法

python - "query"字典的 Pythonic 方式

C# Linq问题

clojure - 从远程 nrepl 传输值