-
-
Save artdent/1623301 to your computer and use it in GitHub Desktop.
Ways by node
This file contains 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 ways-by-node [ways] | |
(reduce | |
(partial merge-with (comp vec concat)) | |
(for [way ways, id (:nodes way)] | |
(hash-map id [(:id way)])))) |
This file contains 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