[Tutor] Matching zipcode in address file

Dave Angel davea at ieee.org
Mon Apr 5 08:32:18 CEST 2010


Alan Gauld wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">
> "TGW" <galaxywatcher at gmail.com> wrote
>
>> I go the program functioning with
>> lines = [line for line in infile if line[149:154] not in match_zips]
>>
>> But this matches records that do NOT match zipcodes. How do I get 
>> this  running so that it matches zips?
>
>
> Take out the word 'not' from the comprehension?
>
That's one change.  But more fundamental is to change the file I/O.  
Since there's no seek() operation, the file continues wherever it left 
off the previous time.

I'd suggest reading the data from the match_zips into a list, and if the 
format isn't correct, doing some post-processing on it.  But there's no 
way to advise on that since we weren't given the format of either file.

zipdata = match_zips.readlines()
Then you can do an      if XXX in zipdata with assurance.

DaveA



More information about the Tutor mailing list