mass editing for keys in a dictionary

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Sep 14 09:25:51 CEST 2007


james_027 a écrit :
> 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}

dict_2 = dict((k[:-3], v) for k, v in dict_1.iteritems())



More information about the Python-list mailing list