I have a python dictionary some_dict
with key (of type PosixPath
) and value (of type tensor
) that looks something like this:
{PosixPath('dataset_small/test/1db4b7f3f65739960cb553b8778982e7e6129e0d.tif'): tensor(0.0053),
PosixPath('dataset_small/test/b1762960a3b92ecc055ce06897378f42bf337c82.tif'): tensor(0.0498),
PosixPath('dataset_small/test/61416795264535918f705f2c93bfd532d23ee8da.tif'): tensor(0.0223),
...
How do I index through this dictionary?
I've tried some_dict['dataset_small/test/' + id + '.tif']
but got the following error:
KeyError
Traceback (most recent call last)
<ipython-input-69-d7a2e0e6db0f> in <module>()
----> 1 pred_list_cor = [pred_dict['dataset_small/test/' + id + '.tif'] for id in sample_list]
<ipython-input-69-d7a2e0e6db0f> in <listcomp>(.0)
----> 1 pred_list_cor = [pred_dict['dataset_small/test/' + id + '.tif'] for id in sample_list]
KeyError: 'dataset_small/test/0b2ea2a822ad23fdb1b5dd26653da899fbd2c0d5.tif'```.