Last active
November 16, 2019 06:47
-
-
Save gsscoder/9862d7c225dc7d7ea36a98af43ec5178 to your computer and use it in GitHub Desktop.
Creates a list of cities in JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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