Paul McGuire a écrit : > On Oct 16, 5:46 am, "Amit Khemka" <[EMAIL PROTECTED]> wrote: > (snip) > Another technique that helps improve script readability is to assign > the results of the split into separate variables, instead of just a > list. This way you can refer to the items with meaningful names > instead of less readable index-into-the-list references: > > for line in open('abc_file'): > datakey,datavalue = line.strip().split('#') > # add the numbers to the 'alphabet' key as a list > d[datakey] = d.get(datakey, []) + [datavalue]
And then use dict.setdefault and list.append: d.setdefault(datakey, []).append(datavalue) -- http://mail.python.org/mailman/listinfo/python-list