Python: How to search input file using dictionary values, append values until certain search string found
<p>I am new to python and have been primarily been using it for parsing of various input files.  I have created a dictionary based on two lists delvt and pin_names.</p>

<p>Using the dictionary, I want to search an input file (netlist) for any values associated with a key. I then want to append the third value in the line to the values portion of the dictionary. Once my search finds a line with "Instance" in it, I want to switch from appending the values section of the dictionary to appending the line of the file with the key from the dictionary. </p>

<p>Sample input file (netlist):</p>

<pre><code>*|NET IN1 0.000466558PF
*|I (X3:GATE X3 GATE I 6.72e-17 0.81 2.19)
*|P (IN1 B 0 0.979 1.259)
*|I (X7:GATE X7 GATE I 5.52e-17 0.81 0.735)
Cg18 X3:GATE 0 1.6885e-16
Cg19 IN1 0 2.48207e-16
Cg20 X7:GATE 0 4.95008e-17
R35 X3:GATE IN1 152.947
R36 X3:GATE X7:GATE 635.085
R37 IN1 X7:GATE 85.6883

*
* Instance Section
*
XX1 X1:DRN X1:GATE X1:SRC X1:BULK pfet ad=0.218p as=0.147p l=0.08u nf=1 pd=2.2u ps=1.619u w=0.84u
XX2 X2:DRN X2:GATE X2:SRC X2:BULK pfet ad=0.13p as=0.14p l=0.08u nf=1 pd=1.132u ps=1.541u w=0.8u
XX3 X3:DRN X3:GATE X3:SRC X3:BULK pfet ad=0.134p as=0.136p l=0.08u nf=1 pd=1.16u ps=1.188u w=0.84u
XX4 X4:DRN X4:GATE X4:SRC X4:BULK pfet ad=0.134p as=0.218p l=0.08u nf=1 pd=1.16u ps=2.2u w=0.84u
</code></pre>

<p>Updated to include code so far:</p>

<pre><code>pin_names = [in0, in1, y]
delvt = [0.100, 0.350, 0.050]
temp = defaultdict(list)
for delvt, pin in zip(delvt, pin_names):
temp[delvt].append(pin)
for line in netlist:
    if re.search .. not sure
</code></pre>

<p>Do I need a for loop iterating through temp and then do the search in each line?</p>

<p>Thanks!</p>
