On 9/14/07, james_027 <[EMAIL PROTECTED]> wrote: > hi, > > How could I transform something like this > > dict_1 = {'customer_id':1, 'item_id':3, amount:100} > > into > > dict_2 = {'customer':1, 'item':3, amount:100}
A one liner would be : >>> dict_2 = dict([(k.split('_')[0], v) for (k,v) in dict_1.iteritems()]) It would split the keys by '_' and use first part of split as the new key ! You must be aware be careful in cases where there are keys like 'customer_1' , 'customer_2', ... Cheers, -- ---- Amit Khemka website: www.onyomo.com wap-site: www.owap.in -- http://mail.python.org/mailman/listinfo/python-list