-
-
Save zaphar/1623184 to your computer and use it in GitHub Desktop.
Ways by node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn collect-ways-by-node [ways] | |
(reduce (fn [m m2] (merge-with #(concat %1 %2) m1 m2)) | |
(for [way ways] | |
(for [id (:nodes way)] | |
(hash-map (:id way) [id]))))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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