Hi Alfonso,<br><br>I see you've had some responses yet -- I've not read them all, and am just posting the following suggestion you might want to look at:<br><br># read lines with "keys" into a list <br>selected_keys=open('A.txt', 'r').readlines()<br>
# read all data records into another list<br>records=open('B.txt', 'r').readlines()<br><br># Now use a list comprehension to return the required entries, the i+1th entries for all i indexes in the records<br>
# list that corresponds to a key in the keys list:<br>selected_values = [(records[i], records[i+1]) for i, row in enumerate(records) if row in selected_keys]<br><br># The above returns both the key and the value, in a tuple, if you just want the value rows only then the above becomes:<br>
#selected_values = [records[i+1] for i, row in enumerate(records) if row in selected_keys]<br><br># Finally print the result.<br>print selected_values<br><br>You'll note I read both files into memory, even though you say your files are largish. I don't consider 500MB to be very large in this day and age of 4+GB PC's, which is why I've basically ignored the "large" issue. If this is not true in your case then you'll have to post back. <br>
<br>Good luck,<br><br>Walter<br>