In an attempt to be slightly more "elegant" (whatever that means ;-) ):
-----8<-----8<----- (def start [{:key 3 :value 10} {:key 6 :value 30}]) (into [] (map (fn [[k v]] {:key k :value v}) (merge (into {} (for [x (range 6)] {x nil})) (into {} (map (juxt :key :value) start))))) ;;=> [{:key 6, :value 30} {:key 0, :value nil} {:key 1, :value nil} {:key 2, :value nil} {:key 3, :value 10} {:key 4, :value nil} {:key 5, :value nil}] -----8<-----8<----- Cheers, Josh On Tuesday, November 19, 2013 at 2:00 PM, Jim - FooBar(); wrote: > On 19/11/13 11:29, Colin Yates wrote: > > In Java I would do something like: > > > > // create a convenient look up to avoid nasty N^2 lookups > > Map<Object, Object> keyToValue = new HashMap.... > > for (Map<Object, Object> kvMap: kvSequence) > > keyToValue.put(kvMap.get("key"), kvMap.put("value")); > > > > List<Object> allKeys = calculateAllKeys(); > > > > List<Map<Object, Object>> results = new Array.... > > for (Object key: allKeys) > > Object result = keyToValue.get(key); // null is fine for missing keys > > results.put(key, result); > > > > return results; > > > this code doesn't do any sorting of keys so I'm not sure it would give > you the exact desired result you posted... > > Jim > > -- > -- > 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 > (mailto: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 > (mailto:clojure+unsubscr...@googlegroups.com) > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com > (mailto:clojure+unsubscr...@googlegroups.com). > For more options, visit https://groups.google.com/groups/opt_out. -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.