[Tutor] Matching zipcode in address file
galaxywatcher at gmail.com
Tue Apr 6 03:35:56 CEST 2010
> OK - you handled the problem regarding reading to end-of-file. Yes it
> takes a lot longer, because now you are actually iterating through
> match_zips for each line.
> How large are these files? Consider creating a set from match_zips. As
> lists get longer, set membership test become faster than list
> If the outfile is empty that means that line[149:154] is never in
> I suggest you take a look at match_zips. You will find a list of
> of length 6, which cannot match line[149:154], a string of length 5.
I am still struggling with this....I have simplified the code, because
I need to understand the principle.
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
I want to output records from filex whose first 3 characters match a
record in zippys. Ouptut:
I am not sure where I should put a '\n' or tweak something that I just
More information about the Tutor