[Tutor] Matching zipcode in address file
alan.gauld at btinternet.com
Mon Apr 5 09:18:43 CEST 2010
Please use Reply All whern responding to the list.
> lines = [line for line in infile if line[149:154] not in match_zips]
>Nope. I tried that. I actually modified your comprehension
>that you provided about a month ago.
>Works great for NOT matching, but can't figure out how to match.
>Do you have another suggestion?def main():
> infile = open("/Users/tgw/NM_2010/NM_APR.txt", "r")
> outfile = open("zip_match_apr_2010.txt", "w")
> match_zips = open("zips.txt", "r")
>You probably are best to read the zips file into a list,
>stripping the newlines:
>matchzips = [match.strip() for match in open('zips.txt')]
> lines = [line for line in infile if line[149:154] in match_zips]
Either that or add a newline to the end of the slice.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor