One formatting detail: there is a blank line after each line
printed, how do I ged rid of the extra blank lines?
lines = [line.strip() for line in infile if line[146:148] not in
omit_states]
print '\n'.join(lines)
This approach stripped leading blank spaces introducing errors into my
fi
But I would do this with a list comprehension or generator
expression (depending on your Python version):
lines = [line for line in infile if line[146:148] not in omit_states]
print '\n'.join(lines)
That's very helpful. Thanks. One formatting detail: there is a blank
line after each line pri
I am trying to output a list of addresses that do not match a list of
State abbreviations. What I have so far is:
def main():
infile = open("list.txt", "r")
for line in infile:
state = line[146:148]
omit_states = ['KS', 'KY', 'MA', 'ND', 'NE', 'NJ', 'PR',
'RI', 'SD', '
I want to share a couple of insights that I had getting started with
Python that I did not come across in the literature all that often. I
am discovering that there are two primary supporting tools needed in
order to create an efficient and productive Python programming
workspace: IDE and V
I finally got it working! I would do a victory lap around my apartment
building if I wasn't recovering from a broken ankle.
Excuse my excitement, but this simple script marks a new level of
Python proficiency for me. Thanks to Kent, Bob, Denis, and others who
pointed me in the right directi
After many more hours of reading and testing, I am still struggling to
finish this simple script, which bear in mind, I already got my
desired results by preprocessing with an awk one-liner.
I am opening a zipped file properly, so I did make some progress, but
simply assigning num1 and num2
I wrote a simple Python script to process a text file, but I had to
run a shell one liner to get the text file primed for the script. I
would much rather have the Python script handle the whole task without
any pre-processing at all. I will show 1) a small sample of the text
file, 2) my scr
This is my first post to the Python tutor list and I just wanted to
introduce myself and give a little background on my skill level prior
to asking for Python advice and programming tips. I am relatively new
to Python, but I have been dabbling with unix shell scripting for at
least 10 years