comparison globalneighbors/neighbors.py @ 20:2fef925fbf37

display country + population in autocomplete drop down
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 16:12:08 -0700
parents
children e69cb496324e
comparison
equal deleted inserted replaced
19:811adc9736eb 20:2fef925fbf37
1 """
2 read neighbors file;
3 this should be in the form of:
4
5 `{geoid: [(geoid_closest_neighbor, distance),
6 (geoid_2nd_closest_neighbor, distance),
7 ...]
8 }`
9 """
10
11 import json
12 import os
13
14 string = (str, basestring) # python2
15
16 def read_neighbors_file(f):
17
18 if isinstance(f, string):
19 with open(f) as _f:
20 return read_neighbors_file(f)
21
22 retval = {}
23 for line in f:
24 data = json.loads(line)
25 retval.update(data)
26 return retval