hi everybody ,i have tried with the improving my code like this but i face the problem since i am not able to concatenate the str, lis...... but if i donot use none i wont get the respective list i require... is there any solution to this
dd = {} dd2 ={} probes = list(enumerate((i.split('\t')[2],i.split('\t')[3], i.split('\t')[4])for i in open('final_lenght_probe_span'))) for idx, (probe_id, span, length) in probes: try : dd[probe_id] = [span,length.strip(),probes[idx+1][1][1]] except IndexError : None = 0( is this a right way) dd[probe_id] = [span,length,None] dd2 = dict(zip(dd.keys(), [[sum(item)] for item in dd.values()])) print dd2 1)the error shown is when i assign NONE =0 None = 0 SyntaxError: assignment to None 2)when i donot assign NONE TypeError: unsupported operand type(s) for +: 'int' and 'str' On 11/1/07, Beema shafreen <[EMAIL PROTECTED]> wrote: > > hi everybody, > I need to sum a list in dictionary... > my script, > d = {} > probes = list(enumerate((i.split('\t')[2],i.split('\t')[3], > i.split('\t')[4])for > i in open('final_lenght_probe_span'))) > for idx, (probe_id, span, length) in probes: > try : > l = [span,length.strip(),probes[idx+1][1][1]] > d[probe_id] = sum[l] > > except IndexError : > none = 0 > l = [span,length,None] > d[probe_id] = sum[l] > for key in d.keys(): > print key, d[key] > > > I used an built-in fuction sum to add the list, but is results in error... > > now how do i do it > > my file used is: > 2709852 2709911 A_16_P21360207 405 -59 > 2710316 2710367 A_14_P136880 -42 -51 > 2710325 2710384 A_16_P21360209 876 -59 > 2711260 2711319 A_16_P21360210 -22 -59 > 2711297 2711356 A_16_P03641959 254 -59 > 2711610 2711659 A_16_P03641960 982 -49 > 2712641 2712696 A_16_P03641962 1011 -55 > 2713707 2713765 A_16_P41563648 43 -58 > 2713808 2713861 A_16_P03641963 -16 -53 > 2713845 2713893 A_16_P41563649 3460 -48 > 2717353 2717412 A_16_P03641964 214 -59 > 2717626 2717685 A_16_P41563655 25 -59 > 2717710 2717754 A_16_P03641965 1250 -44 > > >
-- http://mail.python.org/mailman/listinfo/python-list