Skip to content

Instantly share code, notes, and snippets.

@raeq
Created August 3, 2020 12:32
Show Gist options
  • Save raeq/efc09257887dedc2516454f90e0a3a04 to your computer and use it in GitHub Desktop.
Save raeq/efc09257887dedc2516454f90e0a3a04 to your computer and use it in GitHub Desktop.
Use the CSV package
from collections import defaultdict as dd
import requests
import csv
from pprint import pprint
url: str = "https://data.london.gov.uk/download/london-borough-profiles/c1693b82-68b1-44ee-beb2-3decf17dc1f8/london" "-borough-profiles.csv "
boroughs = (requests.get(url).text).split("\n")
reader = csv.DictReader(boroughs, dialect="excel")
dict1 = dd(dict)
for row in reader:
dict1[row["Code"]] = row
assert dict1["E09000001"]["Area_name"] == "City of London"
assert dict1["E09000032"]["Inner/_Outer_London"] == "Inner London"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment