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
"Christian Witts" wrote
lines = [line for line in infile if line[146:148] not in omit_states]
print ''.join(lines)
Just remember that doing a list comprehension like that on a large file
will drastically reduce the speed of your application as well as
introduce memory bloat.
Given he was
galaxywatc...@gmail.com wrote:
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
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
wrote
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',
'R
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', 'VI', 'VT', 'WI']
for n in omit_states:
if state != n:
print line
infile.close()
ma
galaxywatc...@gmail.com wrote:
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', 'N
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', '