Created
April 16, 2019 18:12
-
-
Save macloo/0d6d2e78a291e3525d8c9a9f5d23fece to your computer and use it in GitHub Desktop.
Take a list of state abbreviations in a text file and put them into a Python list
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
# copy a column from a table into a plain-text file in Atom, save it | |
# mine is named states.txt | |
# here's how to get each line in that file into Python as a list of items | |
myfile = open('states.txt') | |
states_raw = myfile.readlines() | |
# now states_raw holds a list made from lines in states.txt | |
myfile.close() | |
# new empty list for clean strings after stripping | |
states = [] | |
for state in states_raw: | |
states.append(state.strip(' \n')) | |
# print the full list just to see it | |
print(states) | |
len(states) |
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
AL | |
AK | |
AZ | |
AR | |
CA | |
CO | |
CT | |
DE | |
FL | |
GA | |
HI | |
ID | |
IL | |
IN | |
IA | |
KS | |
KY | |
LA | |
ME | |
MD | |
MA | |
MI | |
MN | |
MS | |
MO | |
MT | |
NE | |
NV | |
NH | |
NJ | |
NM | |
NY | |
NC | |
ND | |
OH | |
OK | |
OR | |
PA | |
RI | |
SC | |
SD | |
TN | |
TX | |
UT | |
VT | |
VA | |
WA | |
WV | |
WI | |
WY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment