[Tutor] a dictionary method good for this process

2005-08-04 Thread Srinivas Iyyer
Dear group: I have two lists and I have to match the element in the first list to element in second list and print the line from second list: Example: listA =['apple','baby','cat'] listB =['fruit\tapple','tree\tapple','fruit\tmango', 'human\tbaby' 'infant\tbaby' 'human\tAl

Re: [Tutor] a dictionary method good for this process

2005-08-04 Thread Kent Johnson
Srinivas Iyyer wrote: > Dear group: > > I have two lists and I have to match the element in > the first list to element in second list and print the > line from second list: > > Example: > listA =['apple','baby','cat'] > listB =['fruit\tapple','tree\tapple','fruit\tmango', > 'human\tbaby'

Re: [Tutor] a dictionary method good for this process

2005-08-07 Thread Srinivas Iyyer
Hi Kent: Thank you for your tip on making a sub-dictionary. However, I see some new prbs. that I am unable to solve are persisting. could you enlighten me, please. > d={} > for m in listB: > cols = m.split('\t') > term = cols[1] > d.setdefault(term, []).append(m) > > for i in listA: >

Re: [Tutor] a dictionary method good for this process

2005-08-07 Thread Kent Johnson
Srinivas Iyyer wrote: > Hi Kent: > Thank you for your tip on making a sub-dictionary. > However, I see some new prbs. that I am unable to > solve are persisting. could you enlighten me, please. > > >>d={} >>for m in listB: >> cols = m.split('\t') >> term = cols[1] >> d.setdefault(term, []).a