Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active November 16, 2019 06:47
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 gsscoder/9862d7c225dc7d7ea36a98af43ec5178 to your computer and use it in GitHub Desktop.
Save gsscoder/9862d7c225dc7d7ea36a98af43ec5178 to your computer and use it in GitHub Desktop.
Creates a list of cities in JSON
# file URL: https://raw.githubusercontent.com/gsscoder/test-data/master/largest-cities.csv
import csv
import re
cities = []
with open('largest-cities.csv') as f:
reader = csv.DictReader(f, delimiter=',')
for row in reader:
city = re.sub(r'(\().+?(\))', '', row['City'])
cities.append(f'"{city}"')
json = f'[\n{",".join(cities)}\n]'
json = json.replace(',', ',\n')
print(json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment