[Tutor] Matching zipcode in address file

TGW galaxywatcher at gmail.com
Tue Apr 6 04:47:56 CEST 2010


I got it. I was comparing '345' to '345\n'

Adding the '\n' to the slice did indeed do the trick.

#!/usr/bin/env python

import string

def main():
      infile = open("filex")
      outfile = open("results_testx", "w")
      zips = open("zippys", "r")
      match_zips = zips.readlines()
      lines = [line for line in infile if (line[0:3] + '\n')  in  
match_zips]
      outfile.write(''.join(lines))
#     print lines[0:2]
      zips.close()
      infile.close()
      outfile.close()
main()



More information about the Tutor mailing list