Thanx!, That is exactly what I was looking for!,
Being a clojure newbie and a non-native speaker it is hard to find the correct function among many in clojure core API :-) If only the documentation would provide simple examples like you provided... On 14 okt, 18:20, liebke <lie...@gmail.com> wrote: > Here's one approach: > > (into {} [[:a 1] [:b 2] [:c 3]]) > > => {:a 1, :b 2, :c 3} > > On Oct 14, 11:54 am, Henk <henkp...@gmail.com> wrote: > > > > > Hi All, > > > In Python I was used to be able to easily create dictionaries from > > lists of key value 'pairs' (tuples or list), e.g. like this: > > > dict([(10, 20), (30, 40)]) #using the dict constructor > > => > > {10:20, 30:40} > > > What would be the equivalent in Clojure?, e.g. the normal Clojure hash- > > map function takes a list > > of alternating keys and values which is not quite the same. > > This is a quite common need (especially in the context of initializing > > a hash-map from a list comprehension, like this: > > > (dict (for [x programmers :when ((x :-p rogramming_skills) :java)] > > [(x :id) (str (x :firstname) " " (x :lastname))])) > > > This function seems to do the trick: > > > (defn dict [x] (apply hash-map (apply concat x))) > > > but it is quite slow, e.g. much slower than the python native version > > (I did some small benchmarks on this), while the list comprehension > > itself is much faster than python... -- 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