I have following dictionary,
result =
[{'Img Entropy': 0.4759365334486925,
'Avg Row Entropy': 0.4756050513785311,
'Comp Size, B': 9675063,
'COMP RATIO, out/in': 0.10262087228128054,
'Stack Pos': 3},
{'Img Entropy': 0.4759365334486925,
'Avg Row Entropy': 0.4756050513785311,
'Comp Size, B': 9675063,
'COMP RATIO, out/in': 0.10262087228128054,
'Stack Pos': 3},
{'Img Entropy': 0.4759365334486925,
'Avg Row Entropy': 0.4756050513785311,
'Comp Size, B': 9675063,
'COMP RATIO, out/in': 0.10262087228128054,
'Stack Pos': 3}]
I would like to update the value for 2nd last 'Stack Pos'. When I run the following command, all the 'Stack Pos' keys get updated with value 10.
result[-2]['Stack Pos'] = 10
How can I update/add to only the specific key in the list?
The following function creates the list of dictionaries -
def get_compression_stats(img):
result = []
meta = {}
r = range(0,len(img))
i_e, r_avg_e, r_median_e = get_entropy(img,r)
#iterate over all combinations for each file
comp_parameters = {'typesize':4}
filter_names = ['NONE','SHUFFLE','BITSHUFFLE','BYTEDELTA','SHUFFLE+BYTEDELTA','BITSHUFFLE+BYTEDELTA','SHUFFLE+BITSHUFFLE+BYTEDELTA']
rows_for_blocksize = [0,1,64]
for c in blosc2.compressor_list():
print("Codec: "+str(c))
comp_parameters['codec'] = c
for f in filter_names:
print("Filter: "+f)
comp_parameters['filters'] = get_filter_array(f)
for r in rows_for_blocksize:
comp_parameters['blocksize'] = r*img.shape[1]*img[0][0].nbytes
print("Blocksize: "+ str(comp_parameters['blocksize']))
i_u8 = get_ubyte_img(img)
c_img = blosc2.compress2(i_u8,**comp_parameters)
orig_len, comp_len, blk_size = blosc2.get_cbuffer_sizes(c_img)
c_ratio = comp_len/orig_len
meta['Img Entropy'] = i_e
meta['Avg Row Entropy'] = r_avg_e
meta['Comp Size, B'] = comp_len
meta['COMP RATIO, out/in'] = c_ratio
print("Comp Ratio, out/in: "+ str(c_ratio))
result.append(meta)
return(result)
Thank you.