Beema shafreen wrote: > hi everbody, > I have a file, > a b c d e > 2722316 2722360 A_16_P03641972 150 -44 > 2722510 2722554 A_16_P21360239 16 -44 > 2722570 2722614 A_16_P03641973 44 -44 > 2722658 2722702 A_16_P41563669 2187 -44 > 2724889 2724948 A_16_P03641974 738 -59 > 2725686 2725745 A_16_P03641975 422 -59 > 2726167 2726219 A_16_P03641976 88 -52 > 2726307 2726366 A_16_P41563677 2167 -59 > 2728533 2728589 A_16_P21360249 5819 -56 > 2734408 2734467 A_16_P21360257 -14 -59 > 2734453 2734509 A_16_P03641977 376 -56 > 2734885 2734929 A_16_P21360259 1987 -44 > > i need to do with dictionary like this : c[d,e,d+1] = > A_16_P03641972[150,-44,16] > my script:d = {} > fh = open('final_lenght_probe_span','r') > for line in fh.readlines(): > data = line.strip().split('\t') > probe_id = data[2].strip() > span = data[3].strip() > length = data[4].strip() > d[probe_id ] = [] > d[probe_id] = [span,length,span[0+1]] > for key in d.keys(): > print key ,d[key] > I donot end with this result how do i do.... > >
I'm not sure if this is what you need (check: A_16_P03641972 ['150', '-44', '16']) : >>> d = {} >>> probes = list(enumerate((i.split()[2],i.split()[3], i.split()[4]) for i in open('pyth3.txt'))) >>> for idx, (probe_id, span, length) \ in probes : try : d[probe_id] = [span, length, probes[idx+1][1][1]] except IndexError : d[probe_id] = [span, length, None] >>> for key in d.keys(): print key ,d[key] A_16_P03641974 ['738', '-59', '422'] A_16_P03641975 ['422', '-59', '88'] A_16_P41563669 ['2187', '-44', '738'] A_16_P03641977 ['376', '-56', '1987'] A_16_P03641972 ['150', '-44', '16'] A_16_P03641973 ['44', '-44', '2187'] A_16_P21360249 ['5819', '-56', '-14'] A_16_P41563677 ['2167', '-59', '5819'] A_16_P03641976 ['88', '-52', '2167'] A_16_P21360239 ['16', '-44', '44'] A_16_P21360259 ['1987', '-44', None] A_16_P21360257 ['-14', '-59', '376'] HTH -- http://mail.python.org/mailman/listinfo/python-list