jayjayswal
7/26/2019 - 7:38 AM

dict_key_create_or_update

# setdefault is around 10% faster than get for this purpose. 
# but setdefault won't work if you need Python older than 2.5

transformed_dict={}
for t in transaction_count:
        transformed_dict.setdefault(t['transaction_type'], {}).update({t['peb_transaction_status']:t})
transformed_dict={}
for t in transaction_count:
        transformed_dict.setdefault(t['transaction_type'], []).append(t)
        
        
for key, val in data:
    d1[key] = d1.get(key, []).append(val)
    
for key, val in data:
    d1[key] = d1.get(key, {}).update({k:val})