Skip to content

Instantly share code, notes, and snippets.

@macloo
Created April 16, 2019 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macloo/0d6d2e78a291e3525d8c9a9f5d23fece to your computer and use it in GitHub Desktop.
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
# 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)
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