<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Please reply-all so a copy goes to the list.<br>
<br>
On 4/4/2010 10:02 PM, TGW wrote:
<blockquote cite="mid:C66ED2F5-F1F6-4156-A184-ABBC58B81993@gmail.com"
 type="cite">
  <pre><blockquote type="cite"><pre>&gt;<i> I wrote a script that compares two text files (one zip code file, and 
</i>&gt;<i> one address file)  and tries to output records that match the 
</i>&gt;<i> zipcodes. Here is what I have so far:
</i>&gt;<i>
</i>&gt;<i> #!/usr/bin/env python
</i>&gt;<i> # Find records that match zipcodes in zips.txt
</i>&gt;<i>
</i>&gt;<i> def main():
</i>&gt;<i>     infile = open("/Users/tgw/NM_2010/NM_APR.txt", "r")
</i>&gt;<i>     outfile = open("zip_match_apr_2010.txt", "w")
</i>&gt;<i>     match_zips = open("zips.txt", "r")
</i>&gt;<i>
</i>&gt;<i>     lines = [line for line in infile if line[149:154] in match_zips] # 
</i>&gt;<i> *** I think the problem is here ***
</i>
Yep. You are right.

Try a very simple test case; see if you can figure out what's happening:

infile:
123
234
345

match_zips:
123
234
345

infile = open("infile")
match_zips = open("match_zips")
[line for line in infile if line in match_zips]

Now change infile:
123
244
345
and run the program again.

Interesting, no. Does that give you any insights?
</pre></blockquote><pre>I think I am just lost on this one. I have no new insights. What is the exact program that you want me to run?</pre><pre>
</pre><pre>#!/usr/bin/env python

infile = open("filex")
match_zips = open("zippys")
[line for line in infile if line in match_zips]
print line 
</pre><div>
</div><div>I did what you said and I get '345' output both times.</div></pre>
</blockquote>
<br>
Sorry - my mistake - try: <br>
<br>
<pre><pre>infile = open("filex")
match_zips = open("zippys")
result = [line for line in infile if line in match_zips]
print result 

</pre></pre>
<br>
<pre class="moz-signature" cols="72">-- 
Bob Gailer
919-636-4239
Chapel Hill NC</pre>
</body>
</html>