Processing pairs of values from two sequences in Clojure

前端 未结 3 447
星月不相逢
星月不相逢 2021-02-08 23:42

I\'m trying to get into the Clojure community. I\'ve been working a lot with Python, and one of the features I make extensive use of is the zip() method, for iterating over pair

3条回答
  •  孤街浪徒
    2021-02-09 00:18

    (zipmap [:a :b :c] (range 3))
    -> {:c 2, :b 1, :a 0}
    

    Iterating over maps happens pairwise, e.g. like this:

    (doseq [[k v] (zipmap [:a :b :c] (range 3))]
      (printf "key: %s, value: %s\n" k v))
    

    prints:

    key: :c, value: 2
    key: :b, value: 1
    key: :a, value: 0
    

提交回复
热议问题