gpt4 book ai didi

list - Clojure - 嵌套列表中的对

转载 作者:行者123 更新时间:2023-12-02 21:39:53 25 4
gpt4 key购买 nike

我正在尝试让遍历嵌套列表来收集 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com