gpt4 book ai didi

clojure - 如何将多个序列中的每个元素交织成向量

转载 作者:行者123 更新时间:2023-12-05 00:00:15 26 4
gpt4 key购买 nike

我想从下面以 (vector 开头的序列返回的每个元素创建一个向量。我知道 (vector 是获得我想要的东西的错误方法。它只是一个占位符。

我正在努力解决如何从三个序列中取出第一个元素并得到 ["abc-de-fghi"smith barney] [def-hi-jklm"ox todd],然后是第二个元素,第三个,等等。

感谢您的帮助。

(defn test-key-exclusion
"This function takes csv-data1 (the includees) and tests to see
if each includee is in csv-data2 (the includeds). This function
also gathers enough other data, so that excludees (those not found),
can be identified."

[csv-data1 pkey-idx1 csv-data2 pkey-idx2 lnam-idx fnam-idx]

(let [full-row-ret (map #(ret-non-match-rows csv-data2 pkey-idx2 pkey-idx1 %1) csv-data1)
filtered-row-ret (filter (complement nil?) full-row-ret)]
filtered-row-ret
(vector (map #(nth %1 pkey-idx1 nil) filtered-row-ret)
(map #(nth %1 lnam-idx nil) filtered-row-ret)
(map #(nth %1 fnam-idx nil) filtered-row-ret))))

编辑:解决方案

我用以下方法从多个序列的每个元素创建一个向量。

(defn test-key-exclusion
"This function takes csv-data1 (the includees) and tests to see
if each includee is in csv-data2 (the includeds). This function
also gathers enough other data, so that excludees (those not found),
can be identified."

[csv-data1 pkey-idx1 csv-data2 pkey-idx2 lnam-idx fnam-idx]

(map (fn [row]
(vector (nth row pkey-idx1 nil)
(nth row lnam-idx nil)
(nth row fnam-idx nil)))

(filter (complement nil?)
(map #(ret-non-match-rows csv-data2 pkey-idx2 pkey-idx1 %1) csv-data1))))

最佳答案

我想你需要的只是 map 。它可以接受多个集合:

user> (map vector [1 2 3] [:a :b :c] ["a" "b" "c"])
([1 :a "a"] [2 :b "b"] [3 :c "c"])

关于clojure - 如何将多个序列中的每个元素交织成向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10523326/

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