search re and put in a list??

jubafre at brturbo.com jubafre at brturbo.com
Mon Sep 16 13:41:12 EDT 2002


i have 3 lists:

mem=['7','8', '9']
labels['D1','D2','D3']
S=['20 D1', '30 D2', '10 D3', 'F0', '  3', '  2', '  0']

I want to put mem in s trougth of labels.

#+++++++++++++++++++++++++++++++++++++++++++++
final=[]
for i in range(len(j)):
    for c in range(len(s)):
        p= re.compile(labels[i])
        t1=p.search(s[c])
        if t1:
            t=sub(p, j[i], s[c].strip())
            final.append(t)
print final
#+++++++++++++++++++++++++++++++++++++++++++++

but doing like this i have just de nodes replaced, 
['20 7', '30 8', '10 9']

and i want the replaced and the not replaced in order like this:
['20 7', '30 8', '10 9', 'F0', '  3', '  2', '  0']
	


Juliano Freitas
www.gebrasil.hpg.com.br 


More information about the Python-list mailing list