我有一个我要编号的矢量列表。例如,我有以下内容 载体列表
(["blah1" "blah2" "blah3"]
["clah1" "clah2" "clah3"]
["flah1" "flah2" "flah3"])
并希望这样:
(["line 1" "blah1" "blah2" "blah3"]
["line 2" "clah1" "clah2" "clah3"]
["line 3" "flah1" "flah2" "flah3"])
答案 0 :(得分:2)
map将多个序列作为最后一个参数:
user=> (map vector (iterate inc 1) '(a b c d))
([1 a] [2 b] [3 c] [4 d])
答案 1 :(得分:2)
map-indexed
可以解决问题。
(map-indexed (fn [i v]
(into [(str "line " (inc i))] v))
[["blah1" "blah2" "blah3"]
["clah1" "clah2" "clah3"]
["flah1" "flah2" "flah3"]])
;; => (["line 1" "blah1" "blah2" "blah3"] ["line 2" "clah1" "clah2" "clah3"] ["line 3" "flah1" "flah2" "flah3"])