Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: how to create a hash of nested containers

[Python 3.1]

I am trying to create a hash for a container that may have nested containers in it, with unknown depth. At all levels of the hierarchy, there are only built-in types. What's a good way to do that?

Why I need it:

I am caching the result of some calculations in a pickle object (on disk). I would need to invalidate that cached file if the function is called with different parameters (this happens rarely, so I'm not going to save more than one file to disk). The hash will be used to compare the parameters.

like image 962
max Avatar asked Oct 25 '22 02:10

max


1 Answers

If all the containers are tuples, and all the contained objects are hashable, then the main container should be hashable.

like image 130
Paul Avatar answered Nov 03 '22 00:11

Paul