[Tutor] Matching zipcode in address file

ALAN GAULD 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] 
>Should work...
Either that or add a newline to the end of the slice.


Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100405/e8f12799/attachment.html>

More information about the Tutor mailing list