On Fri, Dec 3, 2010 at 10:08 AM, Laurent PETIT <laurent.pe...@gmail.com> wrote: > 2010/12/3 Laurent PETIT <laurent.pe...@gmail.com> >> 2010/12/3 Anclj <anb...@gmail.com> >>> I've got: >>> >>> user> (split (slurp "data") #",") >>> ["0" "2" "1" "5" "2" "8" "3" "15" "4" "9"] >>> >>> And I would like: >>> {:0 2, :1 5, :2 8, :3 15, :4 9} >>> >>> Any idea? >> >> >> (let [s (split (slurp "data") #",")] >> (zipmap (take-nth 2 s) (take-nth 2 (rest s)))) > > Sorry, this respects the contract better: > > (let [s ["1" "2" "3" "4" "5" "6"]] > (zipmap > (map keyword (take-nth 2 s)) > (map #(Integer/valueOf %) (take-nth 2 (rest s)))))
Both of these traverse s twice. How about: (let [s (split (slurp "data") #",")] (into {} (map (fn [[k v]] [(keyword (str k)) v]) (partition 2 s)))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en