Hi Alan, Thank you again. I did not give a try by using dictionary power. It works now.
Thanks again for tip. -srini. dida = {} for m in nbat: cols = m.split('\t') old = cols[0] dida.setdefault(old,[]).append(cols[1]) lista = ndat.split('\n') result = [] for i in lista: items = dida.get(i) if items is None: result.append(i) else: for x in items: result.append(i+'\t'+x) for x in result: tabs = x.split('\t') if len(tabs)>1: for m in nmlist: cols = m.split('\t') colold = cols[0] colnew = cols[1] if tabs[1] == colold: print x+'\t'+colnew else: print x :-)) RESULT: Contig34839 Contig8376_RC Contig42014_RC Contig25622_RC Contig27915_RC XM_934912 NM_152513 Contig27915_RC XM_934911 NM_152513 Contig27915_RC XM_934908 NM_152513 Contig27915_RC XM_934906 NM_152513 Contig27915_RC XM_934902 NM_152513 Contig27915_RC XM_934901 NM_152513 Contig27915_RC XM_934899 NM_152513 Contig27915_RC XM_934897 NM_152513 Contig27915_RC XM_934896 NM_152513 Contig27915_RC XM_945989 NM_152513 Contig27915_RC XM_945987 NM_152513 Contig27915_RC XM_945986 NM_152513 Contig27915_RC XM_945985 NM_152513 Contig27915_RC XM_945983 NM_152513 Contig27915_RC XM_945982 NM_152513 Contig27915_RC XM_945980 NM_152513 Contig27915_RC XM_945978 NM_152513 Contig27915_RC XM_945977 NM_152513 Contig44682_RC Contig35934_RC Contig29373_RC --- Alan Gauld <[EMAIL PROTECTED]> wrote: > > One of the proble is that, Contig27915_RC is seen > > associated with many XM entries in nbat. However, > > with the above script I could replace only once in > > xta. I could not print Contig27915_RC with many > XM_ > > guys in nbat. How can this be done. > > > > Finally, this whole process seems to be more > > cumbersome to me. Could any one tip me with a new > way > > of dealing this 3 way mapping. > > A common generic way to deal with this is to > construct an > intermediate data model such as a dictionary that > contains > the key element and a list of the keyed items in the > file. > The list could be the items themselves ort a tuple > containing > such info as their index (or seek position). Then > you can iterate > over the data making multiple changes as defined in > the > data structure. > > This is somewhat similar to a thread last month, > take a look > in the archives for more ideas. > > Alan G > Author of the learn to program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld > > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor