Skip to content

Instantly share code, notes, and snippets.

@Glench
Created October 17, 2012 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glench/3906053 to your computer and use it in GitHub Desktop.
Save Glench/3906053 to your computer and use it in GitHub Desktop.
State adjacency in python
# for use with http://writeonly.wordpress.com/2009/03/20/adjacency-list-of-states-of-the-united-states-us/
import csv
import json
from pprint import pprint
with open('states.csv', 'rb') as csvfile:
state_reader = csv.reader(csvfile)
adjacency_dict = {}
for row in state_reader:
adjacency_dict[row[0]] = [state for state in row[1:]]
json_states = json.dumps(adjacency_dict)
pprint(json_states)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment