Skip to content

Instantly share code, notes, and snippets.

@artdent
Forked from zaphar/graph.clj
Created January 16, 2012 22:09
Show Gist options
  • Save artdent/1623301 to your computer and use it in GitHub Desktop.
Save artdent/1623301 to your computer and use it in GitHub Desktop.
Ways by node
(defn ways-by-node [ways]
(reduce
(partial merge-with (comp vec concat))
(for [way ways, id (:nodes way)]
(hash-map id [(:id way)]))))
import collections
def ways_by_node(ways):
ret = collections.defaultdict(list)
for way in ways:
way_id = way['id']
for node_id in way['nodes']:
ret[node_id].append(way_id)
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment