Skip to content

Instantly share code, notes, and snippets.

@sergiolucero
Created October 14, 2017 19:48
Show Gist options
  • Save sergiolucero/c1173589a9e165f96158558d31213826 to your computer and use it in GitHub Desktop.
Save sergiolucero/c1173589a9e165f96158558d31213826 to your computer and use it in GitHub Desktop.
pull population data from Wikipedia
import wikipedia
CITIES=['Paris','Barcelona','Tokyo', 'New York City','Amsterdam','Copenhaguen','San Francisco']
AMBIGUOUS_CITIES = ['Santiago']
for city in CITIES:
citywiki = wikipedia.page(city)
cwsum = citywiki.summary
poploc = cwsum.index('population') # first and only? use re!
print(city, cwsum[poploc:poploc+30])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment