How can I match sequences with IDs using python dictionaries?
Biopython can index a fastafile and you can access the sequences by their ID in a dict-like manner.
All that is left for you to do is extract the IDs from your file. (more Biopython)