comparison globalneighbors/locations.py @ 0:5dba84370182

initial commit; half-working prototype
author Jeff Hammel <k0scist@gmail.com>
date Sat, 24 Jun 2017 12:03:39 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:5dba84370182
1 """
2 location data transformations
3 """
4
5 from .schema import primary_key
6 from .schema import name
7 from collections import OrderedDict
8
9
10 def locations(rows, key=primary_key):
11 """
12 filter out just the location
13 returns a data structure like
14 {key: (lat, lon)
15 ...}
16 """
17
18 return {row[key]: (row['latitude'], row['longitude'])
19 for row in rows}
20
21
22 def city_dict(rows, name=name):
23 """return an ordered dict of cities"""
24
25 return OrderedDict([(row[name], row)
26 for row in rows])
27