Created
October 23, 2016 05:44
-
-
Save mrabbitt/560c14ebf6ba29121806d17f89c00762 to your computer and use it in GitHub Desktop.
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
''' | |
In response to this meme on Facebook: | |
https://www.facebook.com/msaeachubaetsmemes/photos/a.1162336560450433.1073741829.1157905574226865/1168097136541042/?type=3 | |
''' | |
from __future__ import print_function, division, unicode_literals | |
import requests | |
from bs4 import BeautifulSoup | |
url = 'http://www.sec.state.ma.us/ele/eleclk/clkidx.htm' | |
soup = BeautifulSoup(requests.get(url).text) | |
items = soup.find_all('span', attrs={'class': 'citytown'}) | |
names = [x.text.strip() for x in items] | |
count_total = len(names) | |
count_no_o = len([name for name in names if 'O' not in name]) | |
percent_no_o = int(round(count_no_o / count_total * 100)) | |
print('Total number of cities and towns in MA: {}'.format(count_total)) | |
print('Number of cities without "O" in name: {} ({}% of total)'.format(count_no_o, percent_no_o)) | |
print('Based on this list: {}'.format(url)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment