Skip to content

Instantly share code, notes, and snippets.

@raeq
Created August 3, 2020 12:34
Show Gist options
  • Save raeq/322cd7e3a2b447c4b5668d4af7bca69f to your computer and use it in GitHub Desktop.
Save raeq/322cd7e3a2b447c4b5668d4af7bca69f to your computer and use it in GitHub Desktop.
Use the CSV module
from collections import defaultdict as dd
import csv
import requests
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