Skip to content

Instantly share code, notes, and snippets.

@yammesicka
Last active August 9, 2017 08:29
Show Gist options
  • Save yammesicka/624959a3a9ccbbe4dfaec5735045e55b to your computer and use it in GitHub Desktop.
Save yammesicka/624959a3a9ccbbe4dfaec5735045e55b to your computer and use it in GitHub Desktop.
Which states can be spelled out using a single keyboard row
import itertools
import string
import requests
STATES_URL = 'http://www.wefeelfine.org/data/files/states.txt'
KEYBOARD_ROWS = ('qwertyuiop', 'asdfghjkl', 'zxcvbnm')
KEYBOARD = tuple(map(set, KEYBOARD_ROWS))
STATES = tuple(map(set, requests.get(STATES_URL).text.splitlines()))
assert set(string.ascii_lowercase) == set(''.join(KEYBOARD_ROWS))
assert len(STATES) == 50
for state, row_letters in itertools.product(STATES, KEYBOARD):
if state <= row_letters:
print(state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment