Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib2
- import re
- import os.path
- def major_centres(url='http://www.census.gov/popest/cities/tables/SUB-EST2009-01.csv'):
- city_map = [" ".join(x.split(",")[1].split(' ')[:-1]) for x in urllib2.urlopen(url)][4:-5]
- return [x.lower() for x in city_map]
- def all_population_centres_us():
- """download census data file from http://www.census.gov/popest/cities/files/SUB-EST2009-ALL.csv -- 7M, it might take some time
- Returns list of ('city', 'state') tuples
- """
- centre_data = open('SUB-EST2009-ALL.csv', 'r')
- centre_data.readline()
- centres = []
- for k in (tuple(k.split(",")[5:7]) for k in centre_data.readlines()):
- for term in ('town', 'city'):
- if term in k[0]:
- k = (k[0].split(term)[0].strip(), k[1])
- centres.append(k)
- centre_data.close()
- return centres
Advertisement
Add Comment
Please, Sign In to add comment